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

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

问题描述

我有多个项目,但只有一个有 Main 类.具有 Main 类的那个取决于其他项目.这些项目在 Eclipse 中被引用,但是当我导出我的 JAR 时,其他项目不会与该 JAR 一起导出.

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.

如何导出我的主项目并将其他项目包含"到同一个 JAR 中?我宁愿没有几个 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.

推荐答案

不要硬着头皮去做.使用 Eclipse 自己的导出器.首先确保您在主项目的构建路径中将其他项目引用为项目.完成后,只需右键单击主项目,选择 Export,然后选择 Java > Runnable JAR 文件.选择启动配置(您用于在本地测试 main() 类),然后您有 3 个库处理选项来打包 JAR:

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:

第一个选项只会重新打包 JAR 中其他项目的类.一切都简单地放在一起.

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

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

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天全站免登陆