是否可以使用eclipse和share只构建一次java项目? [英] Is it possible to build a java project only once using eclipse and share?
问题描述
是否可以真正构建一个包含要构建一次的java代码并且可以共享二进制文件的maven项目?
问题:我尝试构建的项目大约需要 3-4 个小时,并且需要很高的互联网带宽.我正在尝试检查在其他几台机器中重新使用这个构建的项目的可能性.
我之前曾处理过涉及 makefile 的 C++ 项目,这非常简单.我是 Java/eclipse 的新手,需要帮助来确定这是否真的可行.
附注:我确实试图找到现有的解决方案;他们不是直截了当的,或者他们说这是不可能的.
一次构建,离线分享
在 Maven 中,您可以只构建一次并获得一个包含所有依赖项的 JAR 文件.这样,您就可以离线共享此 JAR 到其他机器.
以下是制作步骤.
<块引用>- 首先使用以下设置更新您的 pom.xml
<插件><插件><artifactId>maven-assembly-plugin</artifactId><配置><存档><清单><mainClass>com.thanga.MyTest[替换为您的主班]</mainClass></清单></归档><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></配置></插件></插件></build>
<小时><块引用>
- 使用目标
package assembly:single
打包您的项目,如下所示
在控制台中,
mvn package assembly:single
在日食中,
<小时><块引用>- 运行这个,你可以得到两个 JAR 文件.其中之一
MyFullPack-0.0.1-SNAPSHOT-jar-with-dependencies.jar
具有完整的已加载依赖项.
- 您可以打开 JAR 以查看依赖项的打包方式,如下所示.
- 您可以离线将这个 JAR 共享给其他机器,而无需进行任何构建
<小时>
Is it possible to actually build a maven project containing java code to be built once and the binaries can be shared?
Problem: The project I am trying to build would take me about 3-4 hours and requires high internet bandwidth. I am trying to check the possibility of re using this built project among several other machines.
I have worked with c++ projects involving makefiles earlier and this was pretty simpler. I am new to Java / eclipse and would need help to figure out if this is something really possible.
PS: I did try to find existing solutions; they were not straight forward or they say that this can't be done.
Build once and share it offline
In Maven, you can build your project only once and get a JAR file fully packed with all dependencies. So that, you can share this JAR to other machines off-line.
Below are the steps to make it.
- First update your pom.xml with the below setting
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.thanga.MyTest[REPLACE WITH YOUR MAIN CLASS]</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
- Package your project with the goal
package assembly:single
as shown below
In console,
mvn package assembly:single
In eclipse,
- Run this and you can get the two JAR files. One of them
MyFullPack-0.0.1-SNAPSHOT-jar-with-dependencies.jar
has the full dependencies loaded.
- You can open the JAR to see the dependencies are packed as shown below.
- You can share this JAR to other machines off-line without any more build
这篇关于是否可以使用eclipse和share只构建一次java项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!