我正在尝试从Java类调用maven。
我的代码:
import java.io.File;
import java.util.Arrays;
import javax.xml.ws.spi.Invoker;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.MavenInvocationException;
public class MavenProjectBuilder implements ProjectBuilder{
public void BuildProject(String buildPath, String bugID) {
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(buildPath));
request.setGoals(Arrays.asList( "clean", "install" ));
DefaultInvoker invoker = new DefaultInvoker();
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/util/cli/StreamConsumer
at autoEvoSuite.MavenProjectBuilder.BuildProject(MavenProjectBuilder.java:21)
at autoEvoSuite.Main.<init>(Main.java:110)
at tests.GeneralTest.main(GeneralTest.java:18)
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.util.cli.StreamConsumer
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 3 more
我做了一些研究,发现它可能是一个缺失的依赖,但不应该Maven自动下载所有缺失的那些?
答案 0 :(得分:0)
请检查POM.xml中是否存在以下依赖项,直到您的pom文件中定义了依赖项,该jar文件将不会下载到本地存储库。
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.17</version>
</dependency>