1

Is there a maven plugin to create a runnable jar which extract all used classes from the dependent libraries?

The main reason I need this is the following: I developed a Java Web Start Application and if I creat the jar with shade plugin or jar plugin the JAR will be >13MB or the shade-plugin even forgets some classes which results in ClassNotFoundException.

With my old ant script the JAR is only 1,3MB small, it contains all required classes and it is downloaded and started really fast. But to go with technology I would like to switch to maven. Thanks a lot!

My current pom:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <shadedClassifierName>min</shadedClassifierName>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

What do I need to add for example the apache chemistry opencmis libraries (now the classes will be extracted but as I said some classes are still missing which opencmis uses itselfe)?

Pali
  • 1,337
  • 1
  • 14
  • 40
  • Have you already looked at the Shade plugin http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html ? It should be able to do the trick, using for instance the _minimizeJar_ option. – Tome Jan 23 '15 at 10:00
  • shade-plugin will not forget classes it sounds more you missed to define some dependencies or have defined as `provided` or `optional` etc. – khmarbaise Jan 23 '15 at 10:11
  • @Tome yes I did but as I also mentioned the Shade plugin does only half its job. The Shade plugin forgets some classes so my application will run into a ClassNotFoundException. Also I can not find the missing class in the jar. The ant script does the work without problems. – Pali Jan 23 '15 at 10:12
  • @khmarbaise oh this could be the problem. Could you take a look at my *pom* and help me? – Pali Jan 23 '15 at 10:20
  • Didn't see the mention @Pali. And I guess khmarbaise is right about the fact that shade-plugin will not forget classes. I guess issue can also come from "literal-defined" dependencies, for instance when using _Class.forName_ or such things. – Tome Jan 23 '15 at 10:47

1 Answers1

0

Please have a look at this question and the suggested workaround - referencing the needed classes to avoid the exclusion by the minimizeJar option.

Community
  • 1
  • 1
gclaussn
  • 1,736
  • 16
  • 19