1

When I run Maven from Eclipse and I generate a JAR, I need to run the JAR in that way from command line, once released:

java -classpath [long list of dependencies] uk.co.superzoom.App

Is it the best way of releasing a JAR or should i change the pom.xml in order to be able to run the JAR in that way:

java -jar myjar.jar

If the second case, two changes would be needed:

1) Add to the manifest the infromation about the main class in order to create a runnable JAR

Main-Class: uk.co.superzoom.App

2) Add all the dependencies automatically, without having to write the long list from command line every time (at the moment they are only visible from Eclipse, but from command line I need to add the long list).

How can I implement the steps (1) and (2) in my pom.xml. Can you provide any example of this?

user1883212
  • 7,539
  • 11
  • 46
  • 82

1 Answers1

1

Use Maven-Shade-Plugin.

From the plugin's page:

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

The plugin bundles all the dependencies into a runable jar file. It also lets you minimize the size of the jar file by using the following code:

<configuration>
  <minimizeJar>true</minimizeJar>
</configuration>

See my question for some information regarding minimization.

Community
  • 1
  • 1
summerbulb
  • 5,709
  • 8
  • 37
  • 83