0

I need a configuration for Maven where all the libraries inside the project are in the final jar in the jar format... So i need to have jars inside the final jar. For that i can only use maven. I already tried without success with plugins like one-jar. Thanks

7
  • Do you want to create only one jar which should contain all the classes from your application and third party libraries ?
    – Sambit
    May 27, 2019 at 8:37
  • Yes but i don't want to have the libraries unpacked in the .class files.
    – Lorenzo
    May 27, 2019 at 8:38
  • 1
    Is it possible to tell why you need jars inside the jar and not class May 27, 2019 at 8:49
  • Because the agency i work for use Serena to deploy the programs and when Serena explode(extract) the jar file in a directory i need to have in this directory the jar files and not the .class
    – Lorenzo
    May 27, 2019 at 8:54
  • Duplicate of stackoverflow.com/questions/11758594/… ?
    – Thilo
    May 27, 2019 at 8:54

2 Answers 2

0

To make a fat jar that includes all you jar files, add the following code to your pom.xml. When you clean and build the project this will automatically make a fat jar file. You need to give your main class inside <mainClass> tag. That's it.

<project>
      <build>
          <plugins>
              <plugin>
                  <artifactId>maven-assembly-plugin</artifactId>
                  <configuration>
                      <archive>
                          <manifest>
                              <addClasspath>true</addClasspath>
                              <mainClass>your.main.class</mainClass>
                          </manifest>
                      </archive>
                      <descriptorRefs>
                          <descriptorRef>jar-with-dependencies</descriptorRef>
                      </descriptorRefs>
                  </configuration>
                  <executions>
                      <execution>
                          <id>final-jar-with-dependencies</id>
                          <phase>package</phase>
                          <goals>
                              <goal>single</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>
    </project>
4
  • Does it contain multiple jar files inside one jar file ?
    – Sambit
    May 27, 2019 at 11:47
  • @Sambit Yes. It will make fat.jar file May 27, 2019 at 11:48
  • I know it will create fat jar, but does that fat jar contain other jar files ?
    – Sambit
    May 27, 2019 at 11:49
  • It contains all the dependencies. (Other jars) Binds all dependencies to the jar file. May 27, 2019 at 11:54
0

Not sure for nested jar because I haven't tried yet.

But I have created .jar file with all project dependencies(specified in pom file)

Try following mvn command in terminal...

mvn org.apache.maven.plugins:maven-assembly-plugin:2.6:assembly -DdescriptorId=jar-with-dependencies package

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.