create an exectuable jar file whose classes reference another jar in Eclipse

P

puzzlecracker

I have jar file with main class. The classes in that jar refernce (aka
import ) class from different jar. Thus when I click on the execuable
jar, iI get noclassfound. How to create executable that will have that
jar in its classpath.
Thanks.

I dont want to merge both jars.
 
J

Jean-Francois Briere

Specify the extra jar files in the META-INF/MANIFEST.MF file:

Class-Path: file1.jar file2.jar ...

Regards
 
J

Jean-Francois Briere

You could also create at the project root the following create_jar.xml
file:

<project name="create_jar" default="create_jar">
<target name="create_jar">
<mkdir dir="jar" />
<jar destfile="jar/myFile.jar">
<fileset dir="bin" />
<manifest>
<attribute name="Main-Class" value="MyClass" />
<attribute name="Class-Path" value="externalFile1.jar
externalFile2.jar" />
</manifest>
</jar>
</target>
</project>

(This will create the jar/myFile.jar jar file
with the files located in bin sub-folder,
with MyClass as main class,
with externalFile1.jar and externalFile2.jar as jars in the search
class path).

Of course, you must change the values appropriately for your project.

When you're ready to create the jar file, simply right-click on the xml
file
in the package explorer window, then select 'Run As' -> '1 Ant Build'

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top