java - 如何配置 exec-maven-plugin 类路径

标签 java maven build continuous-integration exec-maven-plugin

我想执行与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/

相关文章:

javascript - 处理大型 JavaScript 应用程序

Java:在 Java 程序中解释 UTF-8

java - 如何在不复制粘贴代码的情况下复制枚举?

java - 防止与 == 进行字符串比较

java - 如何在 HashMap 中找到关于该元素的给定条件为真的任何元素

maven-jar-plugin 排除失败

ios - xcode 说找不到 ZBarSDK.h,但是它在我的项目中

maven - 如何通过从 Web 界面单击来触发 Junit/Testng 测试运行

java - 如何通过 Maven 命令重新运行 TestNG 失败的测试

build - 在介子中定义外部依赖时,可以添加搜索路径吗?