
For this reason, I need to build a fat jar, which is then executed as a standalone application. I am building a CLI tool, which integrates with several EJB modules. My simplest and always working solution is copy the entire project’s dependencies to a pre-defined folder, and define the dependency classpath in the jar’s manifest file.īelow is the updated and final pom.xml, to use maven-dependency-plugin to copy all dependencies to target/dependency-jars/ folder, and use maven-jar-plugin to add the dependency classpath.Building a standalone executeable JAR with OpenEJB The one-jar solution is really good, but I don’t like the custom class loader and fat-jar concept. – Try one-jar plugin, it will create a fat-jar, which includes the entire project’s dependencies into a single jar file, read this article – Create a fat Jar file with Maven This hack is workable in project with less dependencies only, for large project with many dependencies, it will cause Java class name conflict issue. – Alternatively, use maven-assembly-plugin to extract all dependency jars into raw classes, and group it together. – You can put both log4j.jar and jodatime.jar inside the final.jar, but your classes are unable to call other classes which is inside the unpack log4j.jar, Java jar is designed like this, unless you create a special class loader like one-jar plugin. Update the generated App.java with the following content :Ĥ.1. The following files and folder structure will be created.Ībove folder structure is not enough, create a log4j.properties file and put it in src/main/resources/log4j.properties, just create the resources folder manually. DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false $ mvn archetype:generate -DgroupId= -DartifactId=dateUtils In this tutorial, we will show you how to use Maven build tool, to create a single executable Jar, and how to deal with the project’s dependencies.Ĭreate a Java project from the Maven quick start template.
