Load Properties from resources folder within JAR
11,744
If the property file is inside jar file, it is no longer a physical file
props.load(LazyProperties.class.getResourceAsStream("/properties/movie_libraryproperties"));
Comments
-
Tapas Bose almost 2 years
I have a JAR file Movie Library.jar, its contents are depicted below:
The class PropertiesUtils is resides in the client.jar (shown in picture) and the properties files are in properties folder which resides in resources folder.
I am trying to load properties as:
String absolutePath = LazyProperties.class.getClass().getResource(filePath).getPath(); File file = new File(absolutePath); InputStream stream = new FileInputStream(file); Properties properties = new Properties(); properties.load(stream);
But it is showing:
file:\D:\Code\MovieLibrary\build\jar\Movie%20Library.jar!\resources\properties\movie_library.properties (The filename, directory name, or volume label syntax is incorrect)
I am unable to figure it as
System.out.println(file)
prints:file:/D:/Code/MovieLibrary/build/jar/Movie%20Library.jar!/resources/properties/movie_library.properties
Any help is appreciable. Thanks in advance.
-
Tapas Bose about 12 yearsThanks @Jigar
LazyProperties.class.getResourceAsStream("/resources/properties/movie_library.properties")
did the job. Can you tell me what is the syntax if the resources folder be placed in client.jar? -
jmj about 12 years
LazyProperties.class.getResourceAsStream("classpath:/resources/properties/movie_library.properties")
-
Harshil about 8 years@JigarJoshi : Is there any way if I want to do changes in the property file inside the jar. ?