使用 mvn assembly:single 构建时明显缺少类路径
我正在使用 Maven 和 Eclipse 构建我的项目。我正在使用命令 mvn assembly:single ,它运行得非常愉快。但是,当我尝试使用以下命令运行 jar 时:
java Iris-1.0-SNAPSHOT-jar-with-dependencies.jar
我得到:
Exception in thread "main" java.lang.NoClassDefFoundError: target/Iris-1/0-SNAPSHOT-jar-with-dependencies/jar
Caused by: java.lang.ClassNotFoundException: target.Iris-1.0-SNAPSHOT-jar-with- dependencies.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
此外,清单不包含类路径。生成的清单如下所示
Manifest-Version: 1.0
Built-By: maxgarfinkel
Build-Jdk: 1.6.0_29
Created-By: Apache Maven
Main-Class: com.maxgarfinkel.iris.commandLine.CommandLineTools
Archiver-Version: Plexus Archiver
,pom 如下所示:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maxgarfinkel.iris</groupId>
<artifactId>Iris</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Iris</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.maxgarfinkel.iris.commandLine.CommandLineTools</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swing-layout</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.14</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung2</artifactId>
<version>2.0.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-graph-impl</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.20.1</version>
</dependency>
<dependency>
<groupId>hadoop</groupId>
<artifactId>hadoop</artifactId>
<version>0.20.1</version>
</dependency>
<dependency>
<groupId>hadoop-commons-cli-1.2</groupId>
<artifactId>commons-cli-1.2</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>hadoop-commons-codec-1.3</groupId>
<artifactId>commons-codec-1.3</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>hadoop-commons-el-1.0</groupId>
<artifactId>commons-el-1.0</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>hadoop-commons-httpclient-3.0.1</groupId>
<artifactId>commons-httpclient-3.0.1</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>hadoop-commons-net-1.4.1</groupId>
<artifactId>commons-net-1.4.1</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>hadoop-core-3.1.1</groupId>
<artifactId>core-3.1.1</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>hadoop-hsqldb-1.8.0.10</groupId>
<artifactId>hsqldb-1.8.0.10</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>hadoop-jasper-compiler-5.5.12</groupId>
<artifactId>jasper-compiler-5.5.12</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>hadoop-jasper-runtime-5.5.12</groupId>
<artifactId>jasper-runtime-5.5.12</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>hadoop-jets3t-0.6.1</groupId>
<artifactId>jets3t-0.6.1</artifactId>
<version>0.6.1</version>
</dependency>
<dependency>
<groupId>hadoop-jetty-6.1.14</groupId>
<artifactId>jetty-6.1.14</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>hadoop-jetty-util-6.1.14</groupId>
<artifactId>jetty-util-6.1.14</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>hadoop-kfs-0.2.2</groupId>
<artifactId>kfs-0.2.2</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>hadoop-oro-2.0.8</groupId>
<artifactId>oro-2.0.8</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>hadoop-slf4j-api-1.4.3</groupId>
<artifactId>slf4j-api-1.4.3</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>hadoop-slf4j-log4j12-1.4.3</groupId>
<artifactId>slf4j-log4j12-1.4.3</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>hadoop-xmlenc-0.52</groupId>
<artifactId>xmlenc-0.52</artifactId>
<version>0.52</version>
</dependency>
<dependency>
<groupId>hadoop-zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>colt</groupId>
<artifactId>colt</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.inamik.utils.tableformatter-0.9.1</groupId>
<artifactId>com.inamik.utils.tableformatter-0.9.1</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>Voronoi</groupId>
<artifactId>voronoi</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-algorithms</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-visualization</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-io</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.explodingpixels</groupId>
<artifactId>mac_widgets</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
</project>
1. 如何显示类路径? 2. 这会使 jar 可以运行吗?
I am building my project using maven and eclipse. I am using the command mvn assembly:single which runs quite happily. However when I attempt to run the jar using:
java Iris-1.0-SNAPSHOT-jar-with-dependencies.jar
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: target/Iris-1/0-SNAPSHOT-jar-with-dependencies/jar
Caused by: java.lang.ClassNotFoundException: target.Iris-1.0-SNAPSHOT-jar-with- dependencies.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Also the manifest doesn't contain the class path. The manifest that is produced looks like
Manifest-Version: 1.0
Built-By: maxgarfinkel
Build-Jdk: 1.6.0_29
Created-By: Apache Maven
Main-Class: com.maxgarfinkel.iris.commandLine.CommandLineTools
Archiver-Version: Plexus Archiver
and the pom 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maxgarfinkel.iris</groupId>
<artifactId>Iris</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Iris</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.maxgarfinkel.iris.commandLine.CommandLineTools</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swing-layout</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.14</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung2</artifactId>
<version>2.0.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-graph-impl</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.20.1</version>
</dependency>
<dependency>
<groupId>hadoop</groupId>
<artifactId>hadoop</artifactId>
<version>0.20.1</version>
</dependency>
<dependency>
<groupId>hadoop-commons-cli-1.2</groupId>
<artifactId>commons-cli-1.2</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>hadoop-commons-codec-1.3</groupId>
<artifactId>commons-codec-1.3</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>hadoop-commons-el-1.0</groupId>
<artifactId>commons-el-1.0</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>hadoop-commons-httpclient-3.0.1</groupId>
<artifactId>commons-httpclient-3.0.1</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>hadoop-commons-net-1.4.1</groupId>
<artifactId>commons-net-1.4.1</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>hadoop-core-3.1.1</groupId>
<artifactId>core-3.1.1</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>hadoop-hsqldb-1.8.0.10</groupId>
<artifactId>hsqldb-1.8.0.10</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>hadoop-jasper-compiler-5.5.12</groupId>
<artifactId>jasper-compiler-5.5.12</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>hadoop-jasper-runtime-5.5.12</groupId>
<artifactId>jasper-runtime-5.5.12</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>hadoop-jets3t-0.6.1</groupId>
<artifactId>jets3t-0.6.1</artifactId>
<version>0.6.1</version>
</dependency>
<dependency>
<groupId>hadoop-jetty-6.1.14</groupId>
<artifactId>jetty-6.1.14</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>hadoop-jetty-util-6.1.14</groupId>
<artifactId>jetty-util-6.1.14</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>hadoop-kfs-0.2.2</groupId>
<artifactId>kfs-0.2.2</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>hadoop-oro-2.0.8</groupId>
<artifactId>oro-2.0.8</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>hadoop-slf4j-api-1.4.3</groupId>
<artifactId>slf4j-api-1.4.3</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>hadoop-slf4j-log4j12-1.4.3</groupId>
<artifactId>slf4j-log4j12-1.4.3</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>hadoop-xmlenc-0.52</groupId>
<artifactId>xmlenc-0.52</artifactId>
<version>0.52</version>
</dependency>
<dependency>
<groupId>hadoop-zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>colt</groupId>
<artifactId>colt</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.inamik.utils.tableformatter-0.9.1</groupId>
<artifactId>com.inamik.utils.tableformatter-0.9.1</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>Voronoi</groupId>
<artifactId>voronoi</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-algorithms</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-visualization</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-io</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.explodingpixels</groupId>
<artifactId>mac_widgets</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
</project>
1. How can I get the classpath to show up?
2. WIll that make the jar runnable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要执行此操作
有关更多信息,请参阅此链接
http://docs.oracle.com/javase/tutorial/deployment/jar /run.html
此外,清单也不需要包含类路径(我认为)。
You need to do this
For more information see this link
http://docs.oracle.com/javase/tutorial/deployment/jar/run.html
Also there is no need for the manifest to contain the classpath (I think).