通过maven创建jar的问题

时间:2011-02-17 19:00:37

标签: maven-2 build build-process

HI,

我正在尝试使用maven创建可执行jar。 jar被创建,当我尝试执行java -jar myjar时,我收到以下错误

  

引起:java.lang.ClassNotFoundException:org.apache.hadoop.conf.Configuration       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:202)

我提取了jar,看到hadoop类不存在。在日志中我可以看到没有复制hadoop jar。问题在哪里

我的pom.xml如下:

  

<建立>

     

<插件>

     

<插件>

     

<&的groupId GT; org.apache.maven.plugins< /&的groupId GT;
            < artifactId的>行家编译-插件< / artifactId的>
             <版本> 2.3.1< /版本>
        <结构>
          <信源> 1.6< /源>
          <目标> 1.6< /靶GT;
        < /结构>
      < /插件>
    <插件>
      <&的groupId GT; org.apache.maven.plugins< /&的groupId GT;
      < artifactId的>行家组装-插件< / artifactId的>
      <版本> 2.2-β-4; /版本>
      <结构>
        < descriptorRefs>
          < descriptorRef>罐子与 - 依赖性< / descriptorRef>
        < / descriptorRefs>
        <档案>
          <清单>
            < mainClass> com.MyClass< / mainClass>
          < /清单>
        < /存档>
      < /结构>
      <处决>         <执行>
          <阶段>&包LT; /阶段>
          <目标>
            <目标>单< /目标>
          < /目标>
        < /执行>
      < /处决>
       < /插件>
     < /插件>
     < /构建>

    <!-- 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</version>
    </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>
`

1 个答案:

答案 0 :(得分:1)

您已将hadoop jar指定为范围为<scope>provided</scope>的依赖项 这意味着它们将在运行时位于类路径上,如果您希望它们包含在jar中,则删除范围标记并接受编译的默认范围。

请参阅http://maven.apache.org/pom.html