Marius
Marius

Reputation: 58931

How do I attach properties files to a jar?

I have a project that uses the serial port, and it requires two files to run, the win32.dll file (which is in the java runtime environment bin folder) and the javax.comm.properties file (which is in the java runtime environment lib folder). When I run the project from eclipse it works, but when I try to build a jar file for distribution, it won't work. I suspect this is because the dll and properties files aren't included in the jar. How do I specify that they need to be there?

Upvotes: 4

Views: 7461

Answers (4)

kgiannakakis
kgiannakakis

Reputation: 104178

You generally don't put dll and properties files inside the jar. Properties files as well other jar files need to be added to the classpath. The jar file has a manifest file that defines the classpath used. You can't edit this with eclipse. You need to define an ant build.xml file and do something like this:

<jar jarfile="${dist}/MyJar.jar" basedir="${build}">
  <manifest>
    <attribute name="Main-Class" value="MyClass"/>
    <attribute name="Class-Path" value="."/>
  </manifest>
</jar>

Then put the properties file in the same folder as the jar. You can run the ant target by right clicking the build.xml and selecting the "Run as Ant target".

If I remember correctly, placing the dll file in the bin directory of the jre will work.

Upvotes: 3

guerda
guerda

Reputation: 24049

With Ant, you can pack everything in your Jar you want to. So let Ant create your Jar, not Eclipse :)

Upvotes: 0

l_39217_l
l_39217_l

Reputation: 2110

I think javax.comm.properties just need to be on your classpath. You may can add it to the top level of a jar you delivery.

InputStream is = MainClass.class.getResourceAsStream("javax.comm.properties"); if (is == null) {properties missing....}

I think win32.dll just need to be on the %PATH%(windows) or $LD_LIBRARY_PATH(unix)......

Upvotes: 2

Ot&#225;vio D&#233;cio
Ot&#225;vio D&#233;cio

Reputation: 74280

A jar file is just a normal zip file. If you want to add files to it, just use a tool such as winzip.

Upvotes: 0

Related Questions