是否可以实际构建一个包含 java 代码的 maven 项目一次构建并且二进制文件可以共享?
问题:我尝试构建的项目将花费我大约 3-4 小时,并且需要高互联网带宽。我正在尝试检查在其他几台机器中重新使用这个构建项目的可能性。
我以前处理过涉及 makefile 的 C++ 项目,这非常简单。我是 Java/eclipse 的新手,需要帮助才能确定这是否真的可行。
附言: 我确实尝试找到现有的解决方案;他们不是直截了当的,或者他们说这是不可能的。
最佳答案
构建一次,离线共享
在 Maven 中,您可以构建您的项目仅一次,并获得一个完全包含所有依赖项的 JAR 文件。这样,您就可以离线将此 JAR 共享给其他机器。
下面是制作步骤。
- 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
在控制台中,
mvn package assembly:single
在 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
关于java - 是否可以使用 eclipse 和共享仅构建一次 java 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35217128/