开发者

Problem creating jar through maven

开发者 https://www.devze.com 2023-02-11 07:17 出处:网络
HI, I am trying to creating executable jar using maven. The jar is created and when i try to execute java -jar myjar i get the following error

HI,

I am trying to creating executable jar using maven. The jar is created and when i try to execute java -jar myjar i get the following error

Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

I extracted the jar and see that hadoop classes are not present. And in the logs i could see that hadoop jars are not copied .where is the problem

My pom.xml is as follows :

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>2.3.1</version>

<configuration>

<source>1.6</source>

<target>1.6</target>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-assembly-plugin</artifactId>

<version>2.2-beta-4</version>

<configuration>

<descriptorRefs>

<descriptorRef>jar-with-dependencies</descriptorRef>

</descriptorRefs>

<archive>

<manifest>

<mainClass>com.MyClass</mainClass>

</manifest>

</archive>

</configuration>

<executions> <execution>

<phase>package</phase>

<goals>

<goal>single</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

    <!-- Compile time dependencies -->
<dependency>
  <groupId>bixo</groupId>
 <artifactId>bixo-core</artifactId>
     <version>1.0-SNAPSHOT</version>
</dependency>   
    <dependency>
        <groupId>cascading</groupId>
        <artifactId>cascading-core</artifactId>
    </dependency>

    <dependency>
        <groupId>cascading</groupId>
        <artifactId>cascading-11-jdbc</artifactId>
        <version>0.0.4</version>
    </dependency>

    <dependency>
        <groupId>hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>1.8.0.7</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.0.1</version>
    </dependency>

 <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>0.8</version>
    </dependency>

    <dependency>
        <groupId>org.archive</groupId>
        <artifactId>heritrix</artifactId>
        <version>1.14.3</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</versi开发者_如何学编程on>
    </dependency>

    <dependency>
        <groupId>org.kohsuke</groupId>
        <artifactId>args4j</artifactId>
        <version>2.0.10</version>
    </dependency>


    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>0.21.0-SNAPSHOT</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <artifactId>jetty</artifactId>
                <groupId>org.mortbay.jetty</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jetty-util</artifactId>
                <groupId>org.mortbay.jetty</groupId>
            </exclusion>
        </exclusions>
    </dependency>
  <dependency> 
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapred</artifactId>
            <version>0.21.0-SNAPSHOT</version>
            <scope>provided</scope>
</dependency>
 <dependency> 
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>0.21.0-SNAPSHOT</version>
            <scope>provided</scope>
</dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <!-- Eclipse project generation dependencies -->

    <dependency>
        <groupId>ant-eclipse</groupId>
        <artifactId>ant-eclipse-jvm1.2</artifactId>
        <version>1.0</version>
        <scope>eclipse</scope>
    </dependency>

</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>2.4.1</version>
        </dependency>

        <dependency>
            <groupId>cascading</groupId>
            <artifactId>cascading-core</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>cascading</groupId>
            <artifactId>cascading-test</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>
`


You've specified the hadoop jars as dependencies with a scope of <scope>provided</scope>.
This implies that they will be on the classpath at runtime, if you want them to be included in your jar, then remove the scope tags and accept the default scope of compile.

see http://maven.apache.org/pom.html

0

精彩评论

暂无评论...
验证码 换一张
取 消