如何在Eclipse中构建Java项目来创建外部JAR

时间:2022-03-15 10:36:13

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.

我最近继承了一个用Java编写的大型软件项目。上一个开发人员使用了Eclipse,所以我使用的就是Eclipse,但是我不知道如何构建任何东西。我没有看到任何构建脚本,当我在Eclipse中打开项目时,“构建全部”和“构建项目”选项都是灰色的。

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.

这个项目本质上是一个巨大的包集合,这些包相互依赖。我知道这一定是一个简单的问题,但我还不能通过谷歌搜索或只是在Eclipse上搜索找到答案。我对这个IDE非常陌生——我的职业生涯大部分时间都在Visual Studio工作。如有任何问题或建议,我们将不胜感激。

5 个解决方案

#1


51  

File -> Export -> Export JAR File. Then select your project, press next twice, select the main class.

文件->导出->导出JAR文件。然后选择您的项目,按next两次,选择主类。

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

If you just want to run, open the main class and click the green arrow at the top.

如果您只是想要运行,请打开主类并单击顶部的绿色箭头。

如何在Eclipse中构建Java项目来创建外部JAR

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都会自动构建。您需要自动选择Project -> Build

如何在Eclipse中构建Java项目来创建外部JAR

#2


11  

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.

首先,Eclipse总是在后台构建项目。如果您想要的是可以部署或执行的.jar文件或web归档文件,那么这对您没有多大帮助。如果您需要,关于导出jar的建议是正确的。

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.

现在还不清楚您有多少Java经验,所以我就问这个问题——您确定没有构建脚本吗?寻找名为.pom或build的文件。xml或.gradle文件。如果项目像您说的那样大,我将不得不想象有某种构建脚本/描述符,但是如果您不熟悉Java构建系统,那么您可能就不太清楚了。

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.

Eclipse(以及几乎所有的现代IDE)是一个异常复杂的产品,我们可能给出的任何一两行描述都无法让您在大型代码基上运行。当您在eclipse中打开项目时,在源树的大量类上有红色的“X”图标吗?这是典型的,如果你没有设置好你的库,这又是一个大话题。如果您导入了某人已经完成的项目(或者只是使用了他们的旧开发框),或者您正在从头开始所有这些工作,那么了解这一点将会有所帮助。

#3


3  

you can check the file .project , this file tell eclipse how to build the project. if there are some code as follow:

您可以检查文件.project,这个文件告诉eclipse如何构建项目。如果有以下代码:

<buildSpec>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
</natures>

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.

这是一个java项目。eclipse将以java项目的方式自动构建项目。所以它不需要另一个构建脚本。

#4


1  

normally eclipse build automatically as you add new files. try to clean the project first, maybe you will get an ungreyed build option.

通常,当您添加新文件时,eclipse将自动构建。尝试先清理项目,也许您会得到一个不灰色的构建选项。

do you have java files in the project or just binaries.

在项目中是否有java文件,或者只是二进制文件。

#5


1  

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.

文件>导入>现有项目到工作区。要将项目包含到该文件之后的工作区中—> Export -> Export JAR,以便将其导出到JAR文件中。

#1


51  

File -> Export -> Export JAR File. Then select your project, press next twice, select the main class.

文件->导出->导出JAR文件。然后选择您的项目,按next两次,选择主类。

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

如何在Eclipse中构建Java项目来创建外部JAR

If you just want to run, open the main class and click the green arrow at the top.

如果您只是想要运行,请打开主类并单击顶部的绿色箭头。

如何在Eclipse中构建Java项目来创建外部JAR

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都会自动构建。您需要自动选择Project -> Build

如何在Eclipse中构建Java项目来创建外部JAR

#2


11  

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.

首先,Eclipse总是在后台构建项目。如果您想要的是可以部署或执行的.jar文件或web归档文件,那么这对您没有多大帮助。如果您需要,关于导出jar的建议是正确的。

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.

现在还不清楚您有多少Java经验,所以我就问这个问题——您确定没有构建脚本吗?寻找名为.pom或build的文件。xml或.gradle文件。如果项目像您说的那样大,我将不得不想象有某种构建脚本/描述符,但是如果您不熟悉Java构建系统,那么您可能就不太清楚了。

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.

Eclipse(以及几乎所有的现代IDE)是一个异常复杂的产品,我们可能给出的任何一两行描述都无法让您在大型代码基上运行。当您在eclipse中打开项目时,在源树的大量类上有红色的“X”图标吗?这是典型的,如果你没有设置好你的库,这又是一个大话题。如果您导入了某人已经完成的项目(或者只是使用了他们的旧开发框),或者您正在从头开始所有这些工作,那么了解这一点将会有所帮助。

#3


3  

you can check the file .project , this file tell eclipse how to build the project. if there are some code as follow:

您可以检查文件.project,这个文件告诉eclipse如何构建项目。如果有以下代码:

<buildSpec>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
</natures>

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.

这是一个java项目。eclipse将以java项目的方式自动构建项目。所以它不需要另一个构建脚本。

#4


1  

normally eclipse build automatically as you add new files. try to clean the project first, maybe you will get an ungreyed build option.

通常,当您添加新文件时,eclipse将自动构建。尝试先清理项目,也许您会得到一个不灰色的构建选项。

do you have java files in the project or just binaries.

在项目中是否有java文件,或者只是二进制文件。

#5


1  

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.

文件>导入>现有项目到工作区。要将项目包含到该文件之后的工作区中—> Export -> Export JAR,以便将其导出到JAR文件中。