Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "mvn assembly:single" create a fat jar with just the assemblies and not my code?

I have a maven project I created with spring roo. When I run mvn assembly:single I get a fat jar with all the dependencies, but not the actual code I wrote. Here is my maven-assembly-plugin configuration from my pom.xml:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>net.justaprogrammer.poi.cleanser.Cleanser</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

What am I doing wrong?

like image 632
Justin Dearing Avatar asked Oct 22 '11 20:10

Justin Dearing


People also ask

What is Assembly single in Maven?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.

What is Maven fat jar?

Maven can build a Fat JAR from your Java project. A Fat JAR is a single JAR file that contains all the compiled Java classes from your project, and all compiled Java classes from all JAR files your project depends on (see Maven Dependencies).

Where is jar file maven?

In your project's target directory you'll see the generated jar file which is named like: 'core-1.0-SNAPSHOT. jar'. The resulting 'jar' file contains the compiled java class files as well as the files from src/main/resources.

Does jar file contain dependencies?

Normally, when we package a project into a jarW file, the jar file doesn't contain its dependencies, so the dependency jar files would need to be included in the classpathW in order to execute a class in the project's jar file that uses one of the dependencies.


1 Answers

The solution is to add the single goal to the package phase of the project life cycle. This means you have to add the following xml under the configuration section:

            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
like image 155
Justin Dearing Avatar answered Oct 24 '22 17:10

Justin Dearing