Eclipse:将多个项目打包成一个JAR [英] Eclipse: Package multiple projects into one JAR

查看:979
本文介绍了Eclipse:将多个项目打包成一个JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个项目,但只有一个与主类。主要类别取决于其他项目。这些项目在Eclipse中引用,但是当我导出我的JAR时,其他项目不会与该JAR导出。



如何导出我的主项目并将其他项目包含到同一个JAR中?我不希望有几个JAR,并且必须在命令行上将它们定义到我的Classpath中。

解决方案

不要这是艰难的方式。使用Eclipse自己的导出器。首先,确保在主项目的构建路径中将其他项目引用为项目。一旦完成,只需右键单击主项目,选择导出,然后选择Java> Runnable JAR文件。选择启动配置(用于本地测试 main()类的启动配置),然后选择3个库处理选项来打包JAR :





第一个选项将只是重新包装JAR中其他项目的类。一切都是平坦的一起抛出。



第二个选项将在JAR内将其他项目复制为JAR。这通常不会这样工作,但是Eclipse还添加了一个特殊的启动器,它基本上将嵌入的JAR复制到内存中,在那里提取,将文件添加到类加载器,然后调用 main()与该类加载器。



第三个选项是您不想要的特定情况。


I have multiple projects but only one with a Main class. The one with the Main class depends on the other projects. These projects are referenced in Eclipse, but when I export my JAR, the other projects are not exported with that JAR.

How can I export my Main project and "include" the other projects into that same JAR? I'd rather not have several JARs and have to define them into my Classpath on the command line.

解决方案

Don't do it the hard way. Use Eclipse's own exporter. First ensure that you've the other projects referenced as Projects in the main project's Build Path. Once done that, just rightclick the main project, choose Export and then Java > Runnable JAR file. Choose the launch configuration (which you used to test the main() class locally) and then you've 3 Library Handling options to package the JAR:

The first option will just repackage the classes of other projects inside the JAR. Everything is plain thrown together.

The second option will copy other projects as JARs inside the JAR. This does normally not work that way, but Eclipse also adds a special launcher which basically copies the embedded JARs into memory, extracts there, adds the files to the classloader and then invoke the main() with that classloader.

The third option is something you don't want for this particular case.

这篇关于Eclipse:将多个项目打包成一个JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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