我希望执行与pom.xml位于同一个文件夹中的类文件(或jar文件),其中包含main方法。
这是我的pom.xml
">0.xsd"> 4.0.0图马睡眠时间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存储库,但没有成功。
如何配置此插件以从项目文件夹中找到类?
发布于 2016-08-18 07:30:49
首先,去掉<classpathScope>参数。在Maven中没有名为toumas的范围,只有这些。默认的是runtime,它应该适用于大多数人。
如果您的main方法位于包toumas和文件App.java中,那么它应该可以工作。
你的声明:
“我还试图在插件配置中不指定classpathScope属性,但却得到了以下错误。”
使我怀疑您的Java文件是否真的在src/main/java下。
https://stackoverflow.com/questions/39010573
复制相似问题