MBZ
MBZ

Reputation: 27592

Put and Use .properties file outside Jar

I'm developing a Java Application in Netbeans. The application uses a .properties file (Properties class). The problem is that Netbeans insert this properties file into final .jar file.

  1. How can I make Netbeans not to do this and put the properties file out of jar file?
  2. In this case, how can I use the properties file in code?

Upvotes: 2

Views: 4459

Answers (2)

kevintannguyen
kevintannguyen

Reputation: 67

when you export project by jar formart from Eclipse IDE, you can config it do not import file .properties into jar file.

If you want use .properties file in the same folder with file jar, you can get current path with code:

String path = <NameClass>.class.getProtectionDomain().getCodeSource().getLocation().getPath();

and now, you can load file .properties from above path.

Good luck to you!

Upvotes: 1

duffymo
duffymo

Reputation: 308763

Look at the source directories that NetBeans is asked to insert into the JAR and remove the .properties from the list.

You can always read the .properties file by reading it as an InputStream, as long as it's in the CLASSPATH.

The question is: Why do you feel the need to move it out of that JAR? At least it's in the CLASSPATH that way. You seem to be acting against your own best interests here.

Upvotes: 1

Related Questions