0

I am using TwelveMonkeys library (com.twelvemonkeys.imageio:imageio-tiff:3.1.1) in my project. Also, I am using Maven with maven-dependency-plugin to build my project and I am configuring it like this:

<plugin>
    <!-- Get the dependencies jar files to a common place, for jar signing -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeArtifactIds>commons-net,imageio-psd,imageio-tiff</includeArtifactIds>
                <!-- <includeGroupIds>com.twelvemonkeys.imageio</includeGroupIds> -->
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

The project is getting compiled properly, but its complaining about ClassNotFoundException: com.twelvemonkeys.io.enc.Decoder at runtime. I guess, includeArtifactIds is not including dependencies of the libraries specified inside it (nested dependencies). This is how I am including TwelveMonkeys libraries in my pom.xml:

<dependencies>  
    ...
    <dependency>
        <groupId>com.twelvemonkeys.imageio</groupId>
        <artifactId>imageio-psd</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.twelvemonkeys.imageio</groupId>
        <artifactId>imageio-tiff</artifactId>
        <version>3.1.1</version> <!-- Alternatively, build your own version -->
    </dependency>
    ...
</dependencies>

Could anybody please suggest me how can I include all libraries on which imageio-tiff and imageio-psd depends in my FINAL FAT JAR file? There just got to be a better way to specify "include all dependencies, with there own dependencies".

EDIT:

I am also using ProGaurd for obfuscation with following config:

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.10</version>

    <dependencies>
        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard-base</artifactId>
            <version>5.2</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <executions>
       <execution>
           <phase>package</phase>
           <goals><goal>proguard</goal></goals>
       </execution>
    </executions>
    <configuration>
        <proguardVersion>5.2</proguardVersion>

        <obfuscate>true</obfuscate>
        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}.jar</outjar>
        <outputDirectory>${project.build.directory}</outputDirectory>

        <options>
            <option>-allowaccessmodification</option>
            ...
            <option>-keep public class com.twelvemonkeys.** { *; }</option>
        </options>
        <libs>
            <lib>${java.home}/lib/rt.jar</lib>
            <lib>${java.home}/lib/jsse.jar</lib>
            <lib>${java.home}/lib/jce.jar</lib>
            <lib>${java.home}/lib/plugin.jar</lib>
        </libs>
    </configuration>
</plugin>
Prakhar Mishra
  • 1,586
  • 4
  • 28
  • 52
  • Why do you configure the plugin to select some artifactId? https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.html looks like what you want –  Aug 05 '15 at 14:04
  • @RC, thanks for reply. This example you quoted includes all the libraries (resultant JAR is approx 6 MB now). It makes ProGaurd (obfuscater) little unhappy. Is there a way to just include transitive dependencies of `imageio-*` artifacts? – Prakhar Mishra Aug 05 '15 at 14:17

1 Answers1

0

This is part of my pom.xml to build an .JAR file with all the dependencies included.

<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>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
         </plugin
    </plugins>
</build>

And add to your dependency:

<scope>compile</scope>

I usually build a jar in the following order:

  • Maven Clean
  • Maven Compile
  • Maven Package

This works for me to include all libraries.

Wesley
  • 855
  • 1
  • 9
  • 23
  • Thanks for reply. This sample includes all the libraries (resultant JAR is approx 6 MB now). It makes ProGaurd (obfuscater) little unhappy. Is there a way to just include transitive dependencies of imageio-* artifacts? Thanks. – Prakhar Mishra Aug 05 '15 at 15:14
  • No clue but obfuscating a java application is always a pain in the ass because it is a managed language. If you want something that is compiled to native machine code you should use C++ instead. – Wesley Aug 08 '15 at 15:26