如何从Eclipse导出Java jar并依赖其他jar?

mar*_*arw 5 java eclipse export jar noclassdeffounderror

我正在尝试从Eclipse项目创建一个自包含的.jar文件.通过"自包含",我的意思是该项目的所有依赖项(即其他jar)应该包含在生成的jar中.我想在另一个项目中使用导出的jar作为库.问题是我从依赖项中获取了一个类的NoClassDefFoundError.我已经尝试导出一个包含所有依赖项的runnable jar和一个"普通"jar.这些都不奏效.

清单看起来像这样:

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  
Run Code Online (Sandbox Code Playgroud)

.classpath看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

缺少的类def来自SWT.jar文件.知道什么可能是错的或我需要采取什么步骤才能成功导出这个jar,以便它可以包含在其他地方?

干杯,

马丁

sun*_*nil 12

它可能会帮助某人

1.从项目属性中选择导出

1.选择

2.选择Runnable Jar选项

2. Runnable Jar选项

3.完成JAR创建(在这里,您可以选择将所有依赖项打包到生成的jar中.)

3.完成创作.


mar*_*arw 0

只是回答这个问题:最后,我们决定将依赖项的jar直接包含在项目中,并避免在jar中使用jar。使用 Mavin 也在考虑之中,但需要对我们项目的设置方式进行一些重大改变。