我有一个 java mvn 应用程序,我用mvn assemby:single组装成一个 JAR:
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>se.test.tools.search.CompanyIndexer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>se.test.tools.search.CompanyIndexer</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
该程序集似乎可以工作,但是当我尝试运行 jar 文件时出现错误:
admin:target admin$ java -jar companyindexer-1.0-jar-with-dependencies.jar /Users/admin/Desktop/ PART
Exception in thread "main" java.lang.NoClassDefFoundError: se/test/tools/search/CompanyIndexer
Caused by: java.lang.ClassNotFoundException: se.test.tools.search.CompanyIndexer
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)
se/test/tools/search/CompanyIndexer是我在 pom.xml 中指定为主类的主类。我在这里做错了什么?请注意,我需要发送两个参数。