如何从 Eclipse 导出依赖于其他 jar 的 Java jar? [英] How export Java jar from Eclipse with dependencies on other jars?

查看:48
本文介绍了如何从 Eclipse 导出依赖于其他 jar 的 Java jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Eclipse 项目创建一个独立的 .jar 文件.自包含"是指该项目(即其他 jar)的所有依赖项都应包含在生成的 jar 中.我想在另一个项目中使用导出的 jar 作为库.问题是我从依赖项中得到一个类的 NoClassDefFoundError .我已经尝试导出一个可运行的 jar 并将所有依赖项打包到其中和一个正常"的 jar.这些都不起作用.

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.

清单看起来像这样:

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  

.classpath 如下所示:

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>

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

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?

干杯,

马丁

推荐答案

它可能对某人有帮助

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

1.Select Export from Project Properties

2.选择 Runnable Jar 选项

2.Select Runnable Jar option

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

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

这篇关于如何从 Eclipse 导出依赖于其他 jar 的 Java jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆