Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating library jar with dependent jars with maven dependency plugin

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

like image 778
Nikhil Avatar asked Jun 11 '15 11:06

Nikhil


1 Answers

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.

like image 80
StephaneM Avatar answered Oct 08 '22 04:10

StephaneM