2016-08-18 175 views
1

我想執行位於與包含main方法的pom.xml相同的文件夾中的類文件(或jar文件)。如何配置exec-maven-plugin類路徑

這裏是我的pom.xml

http://maven.apache.org/maven-v4_0_0.xsd「> 4.0.0 圖奧馬斯 睡眠 POM 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倉庫中,但沒有成功。

如何配置此插件從項目文件夾中找到類?

+0

什麼是文件夾結構如下。你有沒有使用maven簡單的原型生成一個初始的腳手架? –

回答

1

首先,擺脫<classpathScope>參數。在Maven中沒有叫做toumas的範圍,只有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下?

+0

'讓我懷疑你的Java文件是否真的在src/main/java?下面。當我在Intellij中創建一個新的Java項目時,發生了什麼事,後來又添加了pom.xml。目錄結構不一樣。 – maksimov