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

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

问题描述

我正在尝试从Eclipse项目创建一个自包含的.jar文件。 自给自足我的意思是这个项目的所有依赖(即其他罐子)应该包含在生成的jar中。我想在另一个项目中使用导出的jar作为库。
问题是我从依赖关系中的一个类中得到一个NoClassDefFoundError。我尝试导出一个可运行的jar,其中包含所有依赖项和一个普通jar。



清单如下所示:

  Manifest-Version:1.0 
主类:com.path.to.MyMainClass
类路径:lib / resolver.jar lib / xercesImpl.jar lib / xml-apis.jar lib / Mac-Cocoa64 /swt.jar

.classpath如下所示:

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

缺少的类def来自SWT.jar文件。
任何想法可能是错误的,或者为了成功导出这个jar可以将其包含在其他地方需要采取哪些步骤?



欢呼,



Martin

解决方案

可能会帮助某人



1.选择从项目属性导出



< img src =https://i.stack.imgur.com/5Hr2e.pngalt =1。选择从项目属性导出>



2.选择Runnable Jar选项





3.清理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.

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

解决方案

It may help someone

1.Select Export from Project Properties

2.Select Runnable Jar option

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

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

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