问题描述
是否可以实际构建一个包含要编译的java代码的maven项目,并且二进制文件可以共享?
is it possible to actually build a maven project containing java code to be built once and the binaries can be shared?
问题:我正在尝试构建项目将需要大约3-4个小时,需要较高的互联网带宽。我试图检查在其他几台机器之间重新使用这个内置项目的可能性。
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.
我早期使用了涉及makefile的c ++项目,这很简单。我是Java / eclipse的新手,需要帮助才能确定这是否真的有可能。
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:
我试图找到现有的解决方案;他们不是星空前进,或者他们说这不能完成
PS:I did try to find existing solutions; they were not staright forward or they say that this cant be done
推荐答案
构建一次并脱机分享
在Maven中,您只能将仅构建一次,并获取完全包装所有依赖关系的JAR文件。所以你可以将这个JAR分享给其他机器。
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.
以下是执行步骤。
- 首先使用以下设置更新您的pom.xml
<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 assembly:single
如下所示
- Package your project with the goal
package assembly:single
as shown below
在控制台中,
mvn package assembly:single
在eclipse中,
- 运行这个,你可以得到两个JAR文件。其中一个
MyFullPack-0.0.1-SNAPSHOT-jar-with-dependencies.jar
具有加载完整的
依赖项。
- 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.
- 您可以打开JAR查看依赖关系如下所示打包。
- 您可以离线共享此JAR到其他机器,无需任何更多的构建>
- You can share this JAR to other machines off-line without any more build
这篇关于是否可以使用eclipse和share来构建一个java项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!