Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linux上运行时,类找不到exec maven插件的异常_Maven_Exec Maven Plugin - Fatal编程技术网

在Linux上运行时,类找不到exec maven插件的异常

在Linux上运行时,类找不到exec maven插件的异常,maven,exec-maven-plugin,Maven,Exec Maven Plugin,我正在尝试运行TestNG测试。我的项目组织是-src->test->java->com->shn->library 下面的命令在Windows中运行良好,但在Linux中失败 mvn -X clean exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e 在Linux中运行同一命令时出现错误- [ERROR] Failed to execute goal o

我正在尝试运行TestNG测试。我的项目组织是-src->test->java->com->shn->library 下面的命令在Windows中运行良好,但在Linux中失败

mvn -X clean exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e
在Linux中运行同一命令时出现错误-

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel
        at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: java.lang.ClassNotFoundException: com.shn.library.RunSuitesInParallel
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
        at java.lang.Thread.run(Thread.java:722)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我跑-

mvn clean install.
当我跑的时候-

mvn -X clean exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e
编译后的类被删除&错误显而易见

所以解决办法是——

mvn -X clean install exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e

虽然被接受的答案很好,但这也可能对某些人有所帮助

似乎在运行依赖于编译类的插件目标之前,您需要确保正在构建Maven项目

如果您创建一个新的java类,在使用插件目标时,会抛出
ClassNotFoundException
,因为该类没有编译版本(插件依赖于该类的编译版本)

假设您在pom.xml中有一个插件配置,如下所示(注意:原文中提到的问题是关于直接运行主类,而不在pom.xml中指定它,并且在接受的答案中解释了如何运行主类)

然后

或者

mvn install exec:java

当使用exec maven插件时,ClassNotFoundException的解决方案很可能是(src\main\java),测试类路径(src\test\java)

它可以在mvn命令(-Dexec.classpathScope=“test”)或pom.xml中传递:

<classpathScope>test</classpathScope>
测试
例如:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
        <executions>
            <execution>
                <phase>test-compile</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>your.package.test.class</mainClass>
                    <arguments>
                        ...
                    </arguments>
                    <classpathScope>test</classpathScope>
                </configuration>
            </execution>
        </executions>
</plugin>

org.codehaus.mojo
execmaven插件
1.6.0
测试编译
JAVA
您的.package.test.class
...
测试

您是否在Linux上运行了
mvn install
来创建jar?是的,我确实尝试过mvn installMy Bad,我确实运行了mvn install。但是,我运行的命令是-mvn clean-X exec:java-Dexec.mainClass=“com.shn.library.RunSuitesInParallel”-Dexec.classpathScope=test-e。因此所有编译的类都被删除了&因此错误显而易见
mvn install exec:java
<classpathScope>test</classpathScope>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
        <executions>
            <execution>
                <phase>test-compile</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>your.package.test.class</mainClass>
                    <arguments>
                        ...
                    </arguments>
                    <classpathScope>test</classpathScope>
                </configuration>
            </execution>
        </executions>
</plugin>