tags:

views:

1169

answers:

4

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?

A: 

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

Otávio Décio
Yes, but will the java application use the file?
Marius
+1  A: 

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)......

l_39217_l
Or set -Djava.library.path=/path/to/win32.dll on the command line (which isn't always an option).
Michael Myers
A: 

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

furtelwart
+3  A: 

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.

kgiannakakis
"The jar file has a manifest file that defines the classpath used. You can't edit this with eclipse." >> Sure you can! Just create your own and point the Export > Jar - wizard to it in the Jar Manifest Specification window..
Tim