Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properties file isn't included in jar file when package Java application

Tags:

java

netbeans

I have developed Java desktop application using Netbeans. In my application, I used some properties files and I placed it under the Project folder so that I can access it by using code like that

 Properties props = new Properties();
 props.load(new FileInputStream("config.properties"));

But when I deploy and package my application to .jar file, I can't find out where properties files are and my application can not read value from properties files.

How can I fix that bug, and where should I place my properties file and load it?

like image 338
Chan Pye Avatar asked Dec 17 '22 03:12

Chan Pye


1 Answers

Put it under /src/resources/, then use it like below.

ResourceBundle props = ResourceBundle.getBundle("resources.config");

NetBeans doesn't include the files under your project directory. Further, you need to build the project, in order to let NetBeans put the properties file inside your /classes directory. Then you should be able to pick it up, by running your application or just a particular related Java class.

Cheers.

like image 87
Adeel Ansari Avatar answered Dec 19 '22 16:12

Adeel Ansari