Skip to content
Advertisement

How to create a non-executable JAR file that includes all Maven dependencies

I have a Java project that doesn’t have a main file but it has a lot of Maven dependencies.

How I can create a JAR-file that contains my source-code and required maven dependencies?

My pom.xml:

JavaScript

Advertisement

Answer

You can use the maven-assembly-plugin just as you could use it for creating an executable JAR with dependencies.

The only thing you need to change is that you don’t need to specify a main class:

JavaScript

After that, you can create the JAR using mvn compile assembly:single.

This compiles your sources and creates a JAR containing the compiled sources and all dependencies in the compile-scope.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement