如何在 Eclipse 中构建 Java 项目以创建外部 JAR
我最近继承了一个用Java编写的大型软件项目。最后一个开发人员使用 Eclipse,所以这就是我正在使用的,但我不知道如何构建任何东西。我没有看到任何构建脚本,当我在 Eclipse 中打开项目时,“Build All”和“Build Project”选项显示为灰色。
该项目本质上是一个相互依赖的软件包的巨大集合。我知道这一定是一个简单的问题,但我无法通过 Google 搜索或仅在 Eclipse 上浏览找到答案。我对这个 IDE 非常陌生 - 我职业生涯的大部分时间都在使用 Visual Studio。如有任何问题/建议,我们将不胜感激。
I recently inherited a large software project written in Java. The last developer used Eclipse, so that's what I'm using, but I can't figure out how to build anything. I don't see any build scripts, and when I open the project in Eclipse the "Build All" and "Build Project" options are greyed out.
The project is essentially a huge collection of packages that depend on one another. I know this has to be a simple question but I haven't been able to find an answer through Googling or through just poking around on Eclipse. I'm very new to this IDE - I have worked with Visual Studio for most of my career. Any questions/suggestions would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
文件->导出->导出 JAR 文件。然后选择您的项目,按两次下一步,选择主类。
如果你只是想运行,打开主类,点击绿色箭头顶部。
如果您只想构建类文件,我相信 Eclipse 会在您每次保存时自动构建。您需要选择项目->自动构建
File -> Export -> Export JAR File. Then select your project, press next twice, select the main class.
If you just want to run, open the main class and click the green arrow at the top.
If you just want to build class files, I believe that Eclipse automatically builds every time you save. You need to select Project -> Build Automatically
首先,Eclipse 总是在后台构建您的项目。如果您想要的是可以部署或执行的 .jar 文件或 Web 存档,那么这对您没有多大帮助。如果您想要的话,关于导出到 jar 的建议是正确的。
目前尚不清楚您有多少 Java 经验,所以我只想问一下 - 您确定没有构建脚本吗?查找名为 .pom 的文件、build.xml 或 .gradle 文件。如果项目像你说的那么大,我不得不想象有某种构建脚本/描述符,但如果你不熟悉Java构建系统,它对你来说可能并不明显。
Eclipse(以及几乎所有现代 IDE)是一种极其复杂的产品,我们提供的任何一两行描述都无法让您在大型代码库上启动和运行。当您在 Eclipse 中打开项目时,源树中的大量类上是否有红色“X”图标?如果您还没有设置好库,那么这是典型的情况,这又是一个大话题。这将有助于了解您是否导入了某人已经拥有的项目(或者只是使用他们的旧开发盒),或者您是否从头开始这一切。
Firstly, Eclipse is always building your project in the background. That doesn't help you much if what you want is a .jar file or web archive that you can deploy or execute. The suggestions about export to jar are correct if that's what you want.
It's not clear how much Java experience you have, so I'll just ask this - are you sure there are no build scripts? Look for files called .pom, or a build.xml or .gradle files. If the project is as large as you say, I would have to imagine there is some sort of build script/descriptor, but if you're not familiar with Java build systems it may not be obvious to you.
Eclipse (and just about any modern IDE) is a monstrously complex product, and any one or two line description we may give won't come close to getting you up and running on a large codebase. When you open the project up in eclipse are there red "X" icons on a ton of classes in the source tree? That's typical if you don't have your libraries all set up, which again, is a big topic. It would help to know if you imported a project someone already had up (or are just using their old development box) or if you're starting all this from scratch.
你可以检查文件 .project ,该文件告诉 eclipse 如何构建项目。
如果有如下代码:
意思是,这是一个java项目。 eclipse 将以 java 项目的方式自动构建项目。
所以它不需要另一个构建脚本。
you can check the file .project , this file tell eclipse how to build the project.
if there are some code as follow:
mean , it's a java project. eclipse will auto build the project in a java project way.
so it don't need another build script.
通常,当您添加新文件时,Eclipse 会自动构建。尝试先清理项目,也许你会得到一个非灰色的构建选项。
你的项目中有java文件还是只有二进制文件。
normally eclipse build automatically as you add new files. try to clean the project first, maybe you will get an ungreyed build option.
do you have java files in the project or just binaries.
文件>导入>现有项目进入工作空间..将项目包含到工作空间中
之后文件 ->导出-> Export JAR 将其导出为 jar 文件。
File > Import > Existing Project into Workspace.. to include the project into the workspace
After that File -> Export -> Export JAR to export it to a jar file.