2011-09-27 149 views
1

我想運行Maven構建後,我的IzPack安裝程序,但我執行「MVN測試」之後得到以下的輸出:如何在maven目標目錄中的JAR文件中運行java類?

[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building RS IzPack installer 
[INFO] task-segment: [test] 
[INFO] ------------------------------------------------------------------------ 
[debug] execute contextualize 
[INFO] [resources:copy-resources {execution: copy-resources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 109 resources 
[INFO] Copying 4 resources 
[INFO] Preparing exec:java 
[WARNING] Removing: java from forked lifecycle, to prevent recursive invocation. 
[debug] execute contextualize 
[INFO] [resources:copy-resources {execution: copy-resources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 109 resources 
[INFO] Copying 4 resources 
[INFO] [exec:java {execution: default}] 
[WARNING] 
java.lang.ClassNotFoundException: com.izforge.izpack.installer.Installer 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:251) 
     at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285) 
     at java.lang.Thread.run(Thread.java:595) 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] An exception occured while executing the Java class. com.izforge.izpack.installer.Installer 

貌似我必須以某種方式把生成的jar文件到類路徑中,任何想法?從我的pom.xml

摘錄:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
     <phase>test</phase> 
     <goals> 
      <goal>java</goal> <!-- "exec" also possible --> 
     </goals> 
     <configuration> 
      <mainClass>com.izforge.izpack.installer.Installer</mainClass> 
      <arguments> 
      <argument>-console</argument> 
      <!-- <argument>arg1</argument> --> 
      </arguments> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

的Apache Maven的2.2.1(r801777; 2009-08-06 21:16:01 + 0200) Java版本:1.6.0_20 Java主: C:\的Java \ jdk16 \ jre的 默認區域:EN_GB,平臺編碼:的Cp1252 操作系統名稱: 「Windows XP中」 版本: 「5.1」 拱 「86」 系列: 「窗口」

馬丁

回答

0

你看過罐子裏面嗎?這可能是因爲maven沒有將所需的類包含到jar中。

+0

是的,我看了我的目標\安裝程序-3.0.0-SNAPSHOT-standard.jar和類com.izforge.izpack.installer.Installer是在罐子裏面。我沒有問題通過運行「java -jar Installer-3.0.0-SNAPSHOT-standard.jar」從cmd行執行它。就像maven一樣,這也是一個問題。 – mkuzela

0

我想你應該使用-classpath來定義java命令的類路徑。你需要構造一個類路徑,它將包含你的主類com.izforge.izpack.installer.Installer及其所有依賴關係。它可以放在一個罐子裏,或者一個類文件夾或多個罐子裏。有關如何爲java調用定義類路徑,請參閱Wikipedia

0

您可以使用類似的東西來定義該執行的依賴性:

<plugin> 
<groupId>org.codehaus.mojo</groupId> 
<artifactId>exec-maven-plugin</artifactId> 
<version>1.2.1</version> 
<executions> 
    <execution> 
    <phase>test</phase> 
    <goals> 
     <goal>java</goal> <!-- "exec" also possible --> 
    </goals> 
    <configuration> 
     <mainClass>com.izforge.izpack.installer.Installer</mainClass> 
     <arguments> 
     <argument>-console</argument> 
     <!-- <argument>arg1</argument> --> 
     </arguments> 
    </configuration> 
    </execution> 
</executions> 
<dependencies> 
    <dependency> 
    <groupId>org.codehaus.izpack</groupId> 
    <artifactId>izpack-standalone-compiler</artifactId> 
    <version>4.3.4</version> 
    <scope>compile</scope> 
    </dependency> 
</dependencies> 

但也有Maven plugin for izpack

相關問題