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>
2
  • Why do you configure the plugin to select some artifactId? maven.apache.org/plugins/maven-dependency-plugin/examples/… looks like what you want Commented Aug 5, 2015 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? Commented Aug 5, 2015 at 14:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.