How to create a fat jar? - java

With SpringBoot, you have the #SpringBootApplication annotation, but what is the equivalent with the neat Java Spark framework?
IntelliJ creates a Maven project and I added the spark dependency, but running the install goal, I get a 5 KB jar with no manifest. Not an executable jar.
The pom.xml created thus far is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sparkdemo</groupId>
<artifactId>sparkdemo</artifactId>
<version>1.0 </version>
<packaging>jar</packaging>
<name>sparkdemo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
</project>
Would appreciate any suggestions....Thanks!

What you need here is an executable jar that will not only contain your classes, but also classes from all your dependencies.
For that you can use the Maven Assembly Plugin.
See the sample code below.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.sample.App</mainClass> // specify your main class here
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</project>
Then, run mvn package and the executable jar should be located in the folder target (with a name like ProjectName-1.0-SNAPSHOT-jar-with-dependencies.jar).

Looks like you are looking for maven assembly plugin
Add this in the plugin section and run mvn package
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Related

jar executable is dysfunctional while it is functional in Netbeans maven project

I have a maven project in Netbeans.
Running it shows a GUI in which you can select and read files using a JFileChooser.
The file chooser has the method getSelectedFiles() which returns a File[] which then I feed into fileProccesing(File[] files) to read them using PDDocument.load(file) from Apache pdfBox depedency.
Debugging has led to the conclusion bellow.
When running in Netbeans it works fine but when it's running as a jar executable it stops at the PDDocument.load(file) command. However no IOException is thrown.
Ether JFileChooser getSelectedFiles() returns some abnormal type of files or my pom.xml is problematic in some way. You can see my pom.xml bellow.
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>application</groupId>
<artifactId>toolToManagePdfs</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>toolToManagePdfs</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.22</version>
</dependency>
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.9.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>
application.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
A normal JAR does not contain or reference its dependencies at runtime. If you want to run a JAR, you need to either
build an executable JAR with the maven assembly plugin or maven shade plugin.
list the classpath explictly when running the JAR.
Here's what I use to have the jar files in the lib subdir:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>application.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
The problem stemmed from having all plugins inside <pluginManagement></pluginManagement>.
Moreover the configuration was incomplete and didn't include the dependencies inside the jar.Using maven-assembly-plugin fixed that.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
application.App
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>

java.lang.NoClassDefFoundError while using maven eclipse AsciidoctorJ

I'm trying to use Asciidoctor to generate an html file using the method built in asciidocj (convertFile)
I'm getting java.lang.NoClassDefFoundError:org/asciidoctor/OptionsBuilder
I'm working on eclipse ; maven and
I added the Asciidoctor dependency in the pom.xml file.
public void view(String document) {
OptionsBuilder op = OptionsBuilder.options().toFile(false);
Asciidoctor asciidoctor = create();
String html = asciidoctor.convertFile(new File(this.path + "/" + document + ".adoc"), op.asMap());
System.out.println(html);
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProgGl</groupId>
<artifactId>PriseDeNotes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PriseDeNotes</name>
<description>Projet de Prog Gl</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<main-class>ProgGl.PriseDeNote.App</main-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${main-class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>${main-class}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.7</version>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
mvn install, package everything is working fine,
when I execute the program I'm getting this error.
I read that it's about class path etc... but I don't understand how to do otherwise
Exception in thread "main" java.lang.NoClassDefFoundError: org/asciidoctor/OptionsBuilder
at ProgGl.PriseDeNote.Application.view(Application.java:171)
at ProgGl.PriseDeNote.Commands.ViewCommand.execute(ViewCommand.java:22)
at ProgGl.PriseDeNote.App.main(App.java:66)
Caused by: java.lang.ClassNotFoundException: org.asciidoctor.OptionsBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
Thank you.
General, the maven assembly plugin generates another .jar called target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar.
You can try java -jar target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar to run the application.
I see you have the maven-assembly-plugin already. Compile with mvn clean compile assembly:single then run with java -jar target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar.
I think the problem is, that maven doesn't copy the dependencies into the jar. Try to copy the dependencies in the target with the related plugin you can find here:
https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html
With this, it should copy the needed dependencies to the target folder.

Java on Heroku can't find Main.class

I am trying to get a very simple Spark app running on Heroku. It runs fine locally. I suspect it's some subtle Maven problem because I've used some Maven scripts from Heroku that I don't quite understand.
Here's my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SparkDemo</groupId>
<artifactId>SparkDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<!-- This tells Maven to include all dependencies -->
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>0.4.4</version>
<configuration>
<jdkVersion>1.8</jdkVersion>
<!-- Use your own application name -->
<appName>still-journey-10861</appName>
<processTypes>
<!-- Tell Heroku how to launch your application -->
<!-- You might have to remove the ./ in front -->
<web>java -jar target/SparkDemo-0.0.1-SNAPSHOT-jar-with-dependencies.jar</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
When I look inside the Jar on Heroku, I see the relevant class right there:
~ $ jar tf target/SparkDemo-0.0.1-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
edu/
edu/brandeis/
edu/brandeis/cosi12b/
edu/brandeis/cosi12b/sparkdemo/
edu/brandeis/cosi12b/sparkdemo/Main.class
edu/brandeis/cosi12b/sparkdemo/StudentChooserServer.class
edu/brandeis/cosi12b/sparkdemo/StudentDirectory.class
edu/brandeis/cosi12b/sparkdemo/StudentInfo.class
studentnames.csv
META-INF/maven/
META-INF/maven/SparkDemo/
META-INF/maven/SparkDemo/SparkDemo/
META-INF/maven/SparkDemo/SparkDemo/pom.xml
META-INF/maven/SparkDemo/SparkDemo/pom.properties
The class name should be complete, with the package too. So instead of <mainClass>Main</mainClass> it should be <mainClass>edu.brandeis.cosi12b.sparkdemo.Main</mainClass>.

Class Not Found Exception for a Maven Jar

I use maven to manage dependency in my project. This is my pom.xml
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.prasanna</groupId>
<artifactId>fft-java</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>fft-java</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.github.wendykierp</groupId>
<artifactId>JTransforms</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.prasanna.TestFFT</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have only one java class in my application. When I run my class from my application, it runs as expected. Whereas if I make a mvn package and try to run it from the terminal as java -jar test-fft.jar, I get a java.lang.ClassNotFoundException: org.jtransforms.fft.DoubleFFT_2D
But this DoubleFFT_2D is a part of JTransforms dependency that I have added. How would I run this jar?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>Mydir/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputDirectory>MyDir</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<mainClass>com.test.entryClassOfJarHavingMainMethod</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Use these configuration in pom.xml to create jar with lib folder and package as a jar
use the maven-assembly plugin to build the jar with dependency.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>

creating a jar-with-dependencies

I am creating a jar-with-dependencies in mvn 3.0.3. I have successfully done this in one project (using just mvn install) and created a complete jar-wth-dependencies. I copied the relevant chunk of POM code (<plugins>...</plugins>, which someone else wrote!) to the current project (which differs in that it has assemblies). It creates the normal snapshot jar (jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar) but no jar-with-dependencies. How should I amend the POM?
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cml</groupId>
<artifactId>jumbo-converters</artifactId>
<version>0.3-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>jumbo-converters-compchem-gaussian</artifactId>
<name>jumbo-converters-compchem-gaussian</name>
<dependencies>
<dependency>
<groupId>${jumbo.groupId}</groupId>
<artifactId>jumbo</artifactId>
</dependency>
<dependency>
<groupId>cml</groupId>
<artifactId>jumbo-converters-core</artifactId>
</dependency>
<dependency>
<groupId>cml</groupId>
<artifactId>jumbo-converters-compchem-common</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cml</groupId>
<artifactId>jumbo-converters-templates</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cml</groupId>
<artifactId>jumbo-converters-testutils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cml</groupId>
<artifactId>jumbo-converters-compchem-testutils</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass>
</manifest>
</archive>
<excludes>
<exclude>.hgsub</exclude>
<exclude>**/.hg/</exclude>
<exclude>**/.project</exclude>
<exclude>**/external/</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass>
</manifest>
</archive>
<excludes>
<exclude>.hgsub</exclude>
<exclude>**/.hg/</exclude>
<exclude>**/.project</exclude>
<exclude>**/external/</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
First,
Use maven dependency plugin to retrieve/store the dependencies (more info here) to your project folder.
Ex: Say lib folder.
Now mark this lib folder as a "Resources" folder.
Like,
<resources>
<resource>
<directory>lib</directory>
<targetPath>lib</targetPath>
</resource>
</resources>
Now mvn install should include the dependencies in your final artifact.
(copying Shinchan's comment to here so it can be formatted:
Simple add this to ur pom.
<build>
<resources>
<resource>
<directory>lib</directory>
<targetPath>lib</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Categories