tags:

views:

617

answers:

6

Hi,

I have created a java application in eclipse, wich needs comm.jar and jexcel.jar and .property files so i have added to libray. I want to make a jar file out of my java appliction, including the external jar files added to the appliction.

How can I do it? To run serialport programs I have copied win32.dll into java_home/bin and comm.jar into java_home/jre/lib and javax.comm.properties into java_home/jre/lib, but when delivering the product it should run only by needing the jre.

How can I solve this? Please help me.

Thanks in advance, suma

+2  A: 

Although your question is not totally clear I suggest using the Fat Jar Plugin should allow you to achieve what you want.

jitter
Out of curiosity, what does this provide that the Executable Jar functionality doesn't have?
dimo414
It just creates a big Jar file with everything (libs, properties, etc) in one file.
borjab
and provides a classloader which can be used to load the dependent jar files from inside the jar, which I believe is not default behaviour.
djna
+2  A: 

You can use File > Export > Executable Jar which includes all libraries. There is also a checkbox to generate an ant build file as well as the jar in order to customize it further (I for instance make all the paths relative and remove the main-class flag).

dimo414
yes,i have created jar as u told it is running but its not recognising any ports,i'm getting no such port exception
I can only imagine that is an error in your code - perhaps you reference a relative file path somewhere? There shouldn't be any problem with the jar file that aren't in your code.
dimo414
I can only imagine that is an error in your code - perhaps you reference a relative file path somewhere? There shouldn't be any problem with the jar file that aren't in your code.Edit: Scratch that, I notice you're also loading DLLs, which may have to be explicitly specified as part of the build, which you have have to do with the Ant file. I've not used DLLs in Java before, so I couldn't say for sure.
dimo414
A: 

You can also check maven.

Macarse
+1  A: 

You have two "path" issues. The Java Classpath and the path from which dlls are loaded.

If you were using a JEE app server or OSGi then controlling these paths is addressed by the respective runtimes. Both JEE and OSGi are likely to be overkill for small projects.

In which case you are delivering:

  1. Your application JAR
  2. The dependent jars
  3. The DLLs

I suggest that on installing your app you place these artefacts into a suitable directory structure, for example .../myapp/lib for the jars and .../myapp/bin for the dlls. Don't copy them into the infrastructure directories, for example the JRE lib and bin, or into Windows32 - that just leads to version nightmares and mysteries when someone installs a new jre.

Having got that structure, how to control the paths? For the classpath, look at the Manifest.mf file. tutorial

For the DLL path, I know of no good alternative to setting OS level environment variables ** before ** launching the JVM. Hence you need a little batch/shell script to launch your app, setting the PATH appropriately.

djna
A: 

You can right click on the project and say "Export". Now select "Java" in tree of choices. Under that select "Jar File". It'll guide you through the process and will allow you to export you project as a jar file.

Hope thats what you are looking for.

Priyank
This doesn't export the dependent libraries as well, however, so they would have to be manually refrenced at run time, which is what the asker is trying to avoid.
dimo414
A: 

The recently released Eclipse 3.5 has a Export as runnable Jar which allows to put all dependent jars in a subfolder to the jar file, and get the Manifest right.

It is an adaption of the FatJar plugin. Works nicely!

Thorbjørn Ravn Andersen