-2

I'm creating a basic app in Java and I'm using a .properties file but when compiled the solution the properties file is not included with the .jar.

How can I add the properties file to the .jar file?

This is the structure of my project:

project

What I did is just add a properties file like this:

properties file

I'm using netbeans 8.0.2, the file is in the same folder of the .java file but I need it in the .jar folder too

2 Answers2

0

That depends on the IDE / build tool.

Generally, place the properties file into the root source folder. That can be something like /src/main/resources (Maven style) or /src itself (Eclipse style), and then recompile.

I don't know the NetBeans layout, but probably similar.

Ralf Kleberhoff
  • 6,990
  • 1
  • 13
  • 7
0

To copy a file (config.properties) into target directory (dist/), you can modify your build.xml:

<target name="-post-compile">
    <copy todir="${dist.dir}">
        <fileset dir="" includes="config.properties"/>
    </copy>
</target>

To package properties file in jar itself, you can just put the properties file into the same directory as your source files. In this case, you can use Class.getResouce() to read it at runtime, but one has to re-package jar to modify it. Source directories are listed under "Source package folders" in project -> properties -> sources.

jurez
  • 4,436
  • 2
  • 12
  • 20