我想执行与pom.xml位于同一文件夹中的类文件(或jar文件),其中包含main方法。
这是我的 pom.xml
http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 托马斯 sleep 聚甲醛 1.0-快照
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>sleep</id>
<phase>verify</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>tuomas.App</mainClass>
<classpathScope>tuomas</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
我收到以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (sleep) on project sleep: Execution sleep of goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java failed: Invalid classpath scope: tuomas -> [Help 1]
这是我的文件夹结构
pom.xml 。 ..tuomas..App.class
我还尝试不在插件配置中指定 classpathScope 属性,但出现以下错误。
[WARNING]
java.lang.ClassNotFoundException: tuomas.App
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:745)
无论类文件是在 tuomas 文件夹下还是在项目根目录中。还尝试将 jar 安装到本地 Maven 存储库,但没有成功。
如何配置此插件以从项目文件夹中查找类?
最佳答案
首先,去掉 <classpathScope>
范围。没有名为 toumas
的范围在 Maven 中,只有 these 。默认为 runtime
这应该适用于大多数人。
提供您的main
方法位于包toumas
中并在文件 App.java
中,它应该可以工作。
您的声明:
"I have also tried not to specify classpathScope attribute in plugin configuration, and got the following error instead."
让我想知道你的Java文件是否真的在src/main/java
下?
关于java - 如何配置 exec-maven-plugin 类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39010573/