Search code examples
javamavenjarjar-with-dependencies

Maven building a jar with dependencies unpacked inside the JAR


I have a problem with jersey 2.14 and nested jars and I can't figure it out. I looked it up and turns out its a bug with jersey which is still being fixed at the moment.

As a workaround I want to be able to use maven to build a jar with all dependencies unpacked inside my jar. I don't want to have JARs inside lib directory, I want classes. And I can't seem to figure out the maven plugin to do this with.

Can anyone help me out with this?

Thanks,


Solution

  • I figured out my issue. I had to use a built in workout of spring boot self. The really smart people there have figured out that there maybe problematic libraries like Jersey.

    You have to use configuration element of spring-boot-maven-plugin.

    Put under any jars that will be needed by Jersey (which have dependencies on other jars)

    Example

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.my.Application</mainClass>
                    <requiresUnpack>
                        <dependency>
                            <groupId>myapp</groupId>
                            <artifactId>service-commons</artifactId>
                            <version>0.1.3</version>
                        </dependency>
                    </requiresUnpack>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>