6

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

marw
  • 403
  • 2
  • 8
  • 17
  • See this: http://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse Hope it works. – bcfurtado Nov 05 '13 at 09:51

2 Answers2

13

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.

sunil
  • 6,444
  • 1
  • 32
  • 44
0

Just to answer this question: In the end, we decided to include the jars of the dependencies directly in the project and avoid havign jars in jars. Using Mavin is also being considered, but would require some substantial chagnes to the way our projects are setup.

marw
  • 403
  • 2
  • 8
  • 17