使用Maven Shade插件时发生ClassNotFound异常
我正在尝试关注此链接: http://maven.apache.org/plugins/maven-shade- plugin/examples.html
I am trying to follow this link: http://maven.apache.org/plugins/maven-shade-plugin/examples.html
我是Maven的新手.尝试按照示例操作时,我感觉有些不合常理.
I am new to Maven. I feel a bit out of depth trying to follow the example.
我能够获得Quartz Scheduler来使用Spring.我希望能够使用jar文件从命令行运行它.
I am able to get Quartz Scheduler to get working with Spring. I want to be able to run it from commandline using jar file.
这是我使用的类和pom文件的列表.
Here are the list of classes and pom file I used.
我能够获得一个阴影jar文件.我使用了mvn clean install
I am able to get a shade jar file. I used mvn clean install
但是当我尝试从命令行运行它时,出现以下错误.
but when I try to run it from the command line, I get the following errors.
C:\Users\SpringExample\target>java -jar SpringExample-1.0-SNA
PSHOT-shaded.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/sonatype/haven/Ex
odusCli
Caused by: java.lang.ClassNotFoundException: org.sonatype.haven.ExodusCli
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.sonatype.haven.ExodusCli. Program will exit.
C:\Users\SpringExample\target>java -jar SpringExample-1.0-SNA
PSHOT-shaded.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/sonatype/haven/Ex
odusCli
Caused by: java.lang.ClassNotFoundException: org.sonatype.haven.ExodusCli
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.sonatype.haven.ExodusCli. Program will exit.
我使用此链接在上面的pom中使用了以下内容:
I used the following in the pom above using this link:
http: //seanfreitag.wordpress.com/2011/07/25/create-an-executable-jar-with-dependencies-using-maven/
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.sonatype.haven.ExodusCli</Main-Class>
<Build-Number>123</Build-Number>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
我没有使用过Shade,但我怀疑:
I haven't used Shade, but I suspect that:
-
您用来调用Shade的pom不会显示
the pom that you are using to invoke Shade is not shown
显示如何设置Main-Class的Maven示例假定org.sonatype.haven.HavenCli类位于正在组装的jar中.
the Maven example showing how to set a Main-Class assumes that the class org.sonatype.haven.HavenCli is somewhere in the jar being assembled
您没有此类课程
您应该将<mainClass>org.sonatype.haven.HavenCli</mainClass>
中的类名称更改为要用作主类的任何名称
you should change the class name in your <mainClass>org.sonatype.haven.HavenCli</mainClass>
to whatever you want to use as a main class