Is it possible to build a java project only once using eclipse and share?

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.

  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

In console,

 mvn package assembly:single

In 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

Leave a Comment