通过maven创建jar的问题
你好,
我正在尝试使用 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 如下:
<构建>
<插件>
<插件>
org.apache.maven.plugins maven-compiler-plugin
<版本>2.3.1
<配置>
<来源>1.6
<目标>1.6
<插件>org.apache.maven.plugins maven- assembly-plugin
<版本>2.2-beta-4
<配置>
<描述符引用>jar-with-dependencies
<存档>
<清单>com.MyClass
<处决> <执行>
<阶段>封装
<目标>
<目标>单个
<!-- 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>
`
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</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>
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将 hadoop jar 指定为范围为
provided
的依赖项。这意味着它们将在运行时位于类路径上,如果您希望将它们包含在 jar 中,请删除范围标签并接受 compile 的默认范围。
请参阅 http://maven.apache.org/pom.html
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