我有一个 Maven 项目 mjbean,它只有一个依赖项:TestA。这是 mjbean 的 pom.xml:
<groupId>com.mbean</groupId>
<artifactId>mjbean</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Main-Class>com.mbean.Main</Main-Class>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<name>mjbean</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.testa</groupId>
<artifactId>TestA</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
主类很简单:
package com.mbean;
import com.testa.Testcl;
public class Main {
public static void main(String[] args) {
Testcl tcl = new Testcl();
tcl.testmethod();
}
}
我已经<Main-Class>com.mbean.Main</Main-Class>
在 maven-bundle-plugin 中指定了主类。它在 Eclipse 中运行良好。然后我使用 Eclipse 在目标文件夹中生成目标包。当我尝试在命令行中运行它时:java -jar mjbean-0.0.1-SNAPSHOT.jar
,我收到了这个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/testa/Testcl
at com.mbean.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: com.testa.Testcl
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
谁能帮我这个?