简体   繁体   中英

How do I build a Java project in Eclipse, to create an external JAR

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.

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

在此输入图像描述

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.

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

<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.

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.

文件>导入>现有项目进入工作区..将项目包含到工作空间之后文件 - >导出 - >导出JAR将其导出到jar文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM