1

I am using Maven to manage a console application project. On my machine, I type mvn exec:java and Maven handles everything. What I want is, however, to execute the same application on a different machine without the help of Maven.

In NetBeans, Ant projects have a dist directory with all the necessary files. All you have to do is to type java -jar dist/App.jar. How can I make Maven generate such distributable directory or archive?

PS: Although seems relevant, this is not a duplicate of Create a standalone application with Maven.

Community
  • 1
  • 1
Eser Aygün
  • 7,794
  • 1
  • 20
  • 30

2 Answers2

4

I have used in maven.

http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/

The Application Assembler Plugin is a Maven plugin for generating scripts for starting java applications. All dependencies and the artifact of the project itself are placed in a generated Maven repository in a defined assemble directory. All artifacts (dependencies + the artifact from the project) are added to the classpath in the generated bin scripts.

and http://maven.apache.org/plugins/maven-assembly-plugin/

The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

You can build an executable jar file with the maven-jar-plugin; more info on their examples page here: http://maven.apache.org/shared/maven-archiver/examples/classpath.html

That will simply create an all-in-one jar that can be executed through java -jar

Yhn
  • 2,785
  • 2
  • 13
  • 10
  • I already use `maven-jar-plugin` but the resulting jar doesn't seem to be "all-in-one". When I execute it, I get `NoClassDefFoundError`s. Do I miss something? – Eser Aygün Feb 23 '12 at 15:20
  • Any dependency defined in the default scope should be repacked into your jar. If you have dependencies on provided scope, they won't be included (as they are assumed to be provided in execution environments, for example EE-jars in an EE project to be deployed in a TomCat EE env). – Yhn Feb 23 '12 at 15:24
  • I thought so too and I gave it another chance but no luck. I am using twitter4j library. Maven downloads and installs it without a problem. But `java -jar` somehow cannot find `twitter4j.StatusListener` class in the target jar file. – Eser Aygün Feb 23 '12 at 15:48
  • Unfortunately Eser is correct. I have been able to recreate the problem. if you crack open the jar file and compare it to a jar file that works, there is a missing boot-inf folder. Not sure how to correct this. – tatmanblue Feb 01 '17 at 01:07