java - 是否可以使用 eclipse 和共享仅构建一次 java 项目?

标签 java eclipse maven

是否可以实际构建一个包含 java 代码的 maven 项目一次构建并且二进制文件可以共享?

问题:我尝试构建的项目将花费我大约 3-4 小时,并且需要高互联网带宽。我正在尝试检查在其他几台机器中重新使用这个构建项目的可能性。

我以前处理过涉及 makefile 的 C++ 项目,这非常简单。我是 Java/eclipse 的新手,需要帮助才能确定这是否真的可行。

附言: 我确实尝试找到现有的解决方案;他们不是直截了当的,或者他们说这是不可能的。

最佳答案

构建一次,离线共享

在 Maven 中,您可以构建您的项目仅一次,并获得一个完全包含所有依赖项的 JAR 文件。这样,您就可以离线将此 JAR 共享给其他机器。

下面是制作步骤。

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

  1. Package your project with the goal package assembly:single as shown below

在控制台中,

 mvn package assembly:single

在 eclipse 中,

enter image description here


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

enter image description here


  1. You can open the JAR to see the dependencies are packed as shown below.

enter image description here


  1. You can share this JAR to other machines off-line without any more build

关于java - 是否可以使用 eclipse 和共享仅构建一次 java 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35217128/

相关文章:

java - 尝试运行 Maven 项目 Java 时如何解决 Unsupported Major.minor version 51.0 错误

eclipse - eclipse 中的 java 构建路径上的编译警告设置在 maven "update project"之后恢复

java - 使用 Java 8 在文本文件中搜索字符串

java - 使用泛型java进行android数据绑定(bind)

java - 使用 lambda 将文本文件转换为 Map<String, List<String>>

java - build.xml ANT 构建中类路径的相对路径

java - 在 Java 中循环遍历列表

java - 如何导入android开源库?

javascript - 使用 PMD Maven 分析 Javascript

java - 如何自动重新加载 App Engine 开发服务器?