mavenuberjar

How to Include a SINGLE dependency into a jar using maven and fatjar plugin


I feel a bit stupid about this question but i can't figure out how to add a SINGLE dependency (jdom.jar) into another jar.

Context: We developed a simple plug-in for our application, this plug-in have many dependency. We were using fatjar to include jdom.jar into it. I am trying to fix a bug in this plug-in, so i decided to "maven-ize" it at the same time. (We just switched to maven) This plug-in is loaded on the runtime so the only dependencies we want packaged with it is the jdom.jar.

Problem: I found that there is a maven fatjar plug-in! Unfortunately i could not find any documentation and this maven plug-in add EVERY dependency into the ouput jar. After many try i decided to give up on this fatjar plug-in and searched for another one. I found one-jar , shade but after a quick read on them they look like they add every dependency.

Question: what would be a simple way to add only jdom.jar into my plug-in jar like this:

-MyPlug-in.jar
|
|-src
 |-main
  |-java
   |-*.java
|-jdom.jar

Also I don't want to alter the manifest or the output jar filename

Thank a lots for your time.


Solution

  • There was no answer here regarding how to use maven to include one single jar-file with the maven-shader-plugin. It took me some time to figure out how to actually do that. Here is a snippet to include just the classes from the dependency com.googlecode.json-simple:json-simple.

    <project>
        ...
        <build>
            <plugins>
                ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <artifactSet>
                                    <includes>
                                       <include>com.googlecode.json-simple:json-simple</include>
                                    </includes>
                                </artifactSet>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
        </build>
        ...
    </project>