Creating library jar with dependent jars with maven dependency plugin

10.9k views Asked by At

I want to create a jar (No main class) which is later used as UDF in apache pig.
When i creating the jar with maven the dependent jars are not include inside the output jar.

pom file looks like this

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>AppName</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>xzloader-java-pig-udf</name>
    <url>http://maven.apache.org</url>

        <build>
    <plugins>
     <plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>2.3.2</version>
       <configuration>
         <source>1.7</source>
         <target>1.7</target>
       </configuration>
    </plugin>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <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>

    <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.8.1</version>
     </dependency>
     <dependency>
        <groupId>org.apache.pig</groupId>
        <artifactId>pig</artifactId>
        <classifier>h2</classifier>
        <version>0.13.0</version>
     </dependency>
    </dependencies>

</project>

But the resulted jar always throw

NoClassDefFoundException

when running with apache pig

1

There are 1 answers

0
StephaneM On

Here is an extract of my pom.xml which builds a jar with dependencies:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>                 
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id> <!-- this is used for inheritance merges -->
                <phase>package</phase> <!-- append to the packaging phase. -->
                <goals>
                    <goal>attached</goal> <!-- goals == mojos -->
                </goals>
            </execution>
        </executions>
    </plugin>

The difference I see is the goal: you use single, I use attached.