My Profile Photo

Cory Kelly


CoryPlusPlus - Cory with classes


A blog documenting solutions to some interesting problems


How to build a jar from third party jars

Have you ever been given an “api” but instead of having everything packaged into a single jar, you were give 20 different jar files and expected to integrate those into your system?

The following will document a solution you can use with maven to create a single manager jar.

  1. Create a new maven project.
  2. Copy all jars into a lib directory (mine is at ${project.basedir}/lib/)
  3. Add the following content to your pom.xml as an initial tempalte
  4. You will need to add an install task for each jar file. This will copy the jar into your m2 directory and allow it to be found during the next step.
                     <execution>
                         <id>install-jar-3</id>
                         <goals>
                             <goal>install-file</goal>
                         </goals>
                         <phase>validate</phase>
                         <configuration>
                             <file>${project.basedir}/lib/common-1.4.56.jar</file>
                             <groupId>com.dds</groupId>
                             <artifactId>common-1.4.56</artifactId>
                             <version>1.0</version>
                             <packaging>jar</packaging>
                             <generatePom>true</generatePom>
                         </configuration>
                     </execution>
    
  5. Create a dependency entry
         <dependency>
             <groupId>com.dds</groupId>
             <artifactId>common-1.4.56</artifactId>
             <version>1.0</version>
         </dependency>
    
  6. run mvn install
  7. Open target directory and your new jar should be waiting
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.coryplusplus</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>axis-1.4</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>axis-jaxrpc-1.4</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>common-1.4.56</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>commons-discovery-0.2</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>commons-logging-1.0.4</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>dnsns</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>epsiia-dx-wsa-client-1.4.30</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>exception-1.2.1</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>jaccess</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>junit-4.2</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>localedata</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>log4j-1.2.13</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>logging-1.2.6</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>sunec</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>sunjce_provider</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>sunmscapi</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>testUtils-1.0.0</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>xercesImpl-2.8.0</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>xml-apis-1.3.03</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.dds</groupId>
            <artifactId>axis-1.4</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <!-- any other plugins -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>

                <executions>
                    <execution>
                        <id>install-jar-1</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/axis-1.4.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>axis-1.4</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-2</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/axis-jaxrpc-1.4.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>axis-jaxrpc-1.4</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-3</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/common-1.4.56.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>common-1.4.56</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-4</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/commons-discovery-0.2.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>commons-discovery-0.2</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-5</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/commons-logging-1.0.4.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>commons-logging-1.0.4</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-6</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/dnsns.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>dnsns</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-7</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/epsiia-dx-wsa-client-1.4.30.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>epsiia-dx-wsa-client-1.4.30</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-8</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/exception-1.2.1.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>exception-1.2.1</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-9</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/jaccess.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>jaccess</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-10</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/junit-4.2.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>junit-4.2</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-11</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/localedata.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>localedata</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-12</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/log4j-1.2.13.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>log4j-1.2.13</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-13</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/logging-1.2.6.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>logging-1.2.6</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-14</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/sunec.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>sunec</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-15</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/sunjce_provider.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>sunjce_provider</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-16</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/sunmscapi.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>sunmscapi</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-17</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/testUtils-1.0.0.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>testUtils-1.0.0</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-18</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/xercesImpl-2.8.0.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>xercesImpl-2.8.0</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-19</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/xml-apis-1.3.03.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>xml-apis-1.3.03</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-jar-20</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <file>${project.basedir}/lib/zipfs.jar</file>
                            <groupId>com.dds</groupId>
                            <artifactId>zipfs</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>

                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>


                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>

            </plugin>
        </plugins>

    </build>

</project>

comments powered by Disqus