【问题标题】:How to configure exec-maven-plugin classpath如何配置 exec-maven-plugin 类路径
【发布时间】:2016-12-24 22:25:30
【问题描述】:

我想执行与 pom.xml 位于同一文件夹中的类文件(或 jar 文件),其中包含 main 方法。

这是我的 pom.xml

http://maven.apache.org/maven-v4_0_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 存储库,但没有成功。

如何配置此插件以从项目文件夹中查找类?

【问题讨论】:

  • 文件夹结构如下。您是否使用 maven 简单原型生成初始脚手架?

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


【解决方案1】:

首先,去掉&lt;classpathScope&gt; 参数。 Maven 中没有名为toumas 的作用域,只有these。默认为runtime,应该适用于大多数人。

如果您的 main 方法位于包 toumas 和文件 App.java 中,它应该可以工作。

您的陈述:

“我也试过在插件配置中不指定classpathScope属性,结果报如下错误。”

让我怀疑你的 Java 文件是否真的在 src/main/java 下?

【讨论】:

  • makes me wonder if your Java file really is under src/main/java? 正是我在 Intellij 中创建一个新的 Java 项目并随后将 pom.xml 添加到其中时发生的事情。目录结构不一样。
  • 附带说明,您的答案指向了错误的范围。这是依赖范围,而正确的引用是 classpathScope
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-15
  • 2020-01-01
  • 2011-01-12
  • 2016-11-21
  • 2011-10-22
  • 2013-03-19
  • 2012-03-03
相关资源
最近更新 更多