Null pointer exception while reading a properties file

propsdatabase = new Properties();
InputStream dbin = getClass().getResourceAsStream("/properties/database.properties");
propsdatabase.load(dbin);

I am reading database connection data through a properties file called "database.properties" in a folder named "properties". Jus below the root directory.

The code worked fine when the container was exported to Eclipse.

But I used the Maven project in IntelliJ to get the jar. It throws a NUll pointer exception.

Since the value of dbin is NULL. (I printed and checked as well).

I conclude that the path is not recognized for reading the file.

Now all is well with IntelliJ.

When exporting as a jar to Eclipse Bank, although it contains a folder with its own names, IT was not detected. help with

+3
source share
4 answers

, getResourceAsStream null, , /properties/database.properties Maven.

/src/main/resources, Maven jar, /properties/database.properties, NPE.

+2

, getResourceAsStream, , null. , jar . :

jar tvf yourfile.jar

. jar. , , , , , , , , .

+1

maven ? jar. , ".zip" .

0

FileInputStream:

Properties properties = new Properties();
FileInputStream input = null;
try {
   input = new FileInputStream(new File(CONFIGURATION_FILE));
   properties.load(input);
}catch(...){...}
0

All Articles