Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How export Java jar from Eclipse with dependencies on other jars?

I am trying to create a self-contained .jar file from an Eclipse project. By "self-contained" I mean that all dependenies of this project (i.e. other jars) should be included in the generated jar. I would like to use the exported jar in another project as a library. The problem is that I get a NoClassDefFoundError for one of the classes from the dependencies. I have tried exporting both a runnable jar with all dependencies packaged into it and a "normal" jar. Neither of these works.

The manifest looks like this:

Manifest-Version: 1.0
Main-Class: com.path.to.MyMainClass
Class-Path: lib/resolver.jar lib/xercesImpl.jar lib/xml-apis.jar lib/Mac-Cocoa64/swt.jar  

The .classpath look like this:

<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="lib/resolver.jar"/>
    <classpathentry kind="lib" path="lib/xercesImpl.jar"/>
    <classpathentry kind="lib" path="lib/xml-apis.jar"/>
    <classpathentry kind="lib" path="lib/Mac-Cocoa64/swt.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

The missing class def is from the SWT.jar file. Any idea what might be wrong or what steps I need to take in order to successfully export this jar so that it can be included elsewhere?

Cheers,

Martin

like image 902
marw Avatar asked Nov 05 '13 09:11

marw


1 Answers

It may help someone

1.Select Export from Project Properties

1. Select Export from Project Properties

2.Select Runnable Jar option

2. Runnable Jar option

3.Finish the JAR creation (Here, you have the option to package all dependencies into the generated jar.)

3. Finish the creation.

like image 179
sunil Avatar answered Sep 30 '22 09:09

sunil