Maven not adding all dependencies to jar

I've a simple program build in IntelliJ and using maven that uses the dependency io.netty. I've added to my POM file:

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.1.0.Beta1</version>
    </dependency>

In order to compile and get a jar file I usually do:

  • Clean
  • Compile
  • Package

However I noticed that the dependency is not added to the jar, neither existing in the target folder (Or in any of it's sub folders) or added to the resources folder like usually happens.

In order to have the io.netty library to be added to the jar I have tried:

  • Setting the scope to provided and to compile.
  • Re-importing the pom file.
  • Deleting io.netty folder in the .m2/repository/ folder.

I have several other libraries linked including:

  • mysql-connector-java
  • slf4j-simple
  • trove4j

Thanks for reading.

Answers


For some odd reason I had changed my maven configuration a while ago. While I had not added any new libraries, the old ones still had their classes laying around therefor still being added to the jar.

I solved this issue by changing the build in my pom to:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.domain.Program</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Used as reference: http://mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/


Maven doesn't package all dependencies into a jar by default. You can use the assembly plugin to build a "jar with dependencies, as seen here: How can I create an executable JAR with dependencies using Maven?


Need Your Help

Can you use a for loop to implement a sentinel controlled loop in Python?

python

I'm not too sure if there might have been another duplicate, but question as per topic.

Copying Stream from XmlTextWriter to a FileStream

.net vb.net stream

I have an HTTP Handler that is binding an XmlTextWriter instance to Response.Output like so...