2012-03-22 209 views
1

我想使用maven和launch4j將基於java的命令行應用程序及其所有依賴項包裝到單個* .exe文件中。使用launch4j和maven包裝java命令行應用程序

現在我已閱讀所有類似的問題,例如this onethis,但我無法使其工作。

任何人都可以提供一個簡單的pom.xml片段,如何實現這一點與所有需要的依賴關係。 順便說一下,我應該在Eclipses運行配置中運行哪些maven構建目標?

以下是我從SO複製:

<!-- Launch4j --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one --> 
       <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar --> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.bluestemsoftware.open.maven.plugin</groupId> 
      <artifactId>launch4j-plugin</artifactId> 
      <version>1.5.0.0</version> 
      <executions> 

       <!-- Command-line exe --> 
       <execution> 
        <id>l4j-cli</id> 
        <phase>package</phase> 
        <goals> 
         <goal>launch4j</goal> 
        </goals> 
        <configuration> 
         <headerType>console</headerType> 
         <outfile>target/importer.exe</outfile> 
         <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above --> 
         <errTitle>App Err</errTitle> 
         <classPath> 
          <mainClass>${mainClass}</mainClass> 
         </classPath>     
         <jre> 
          <minVersion>1.5.0</minVersion> 
          <maxVersion>1.6.0</maxVersion> 
          <initialHeapSize>128</initialHeapSize> 
          <maxHeapSize>1024</maxHeapSize> 
         </jre> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

當我運行launch4j:(?如果這是正確的)launch4j目標在Eclipse中,我得到:

未能執行目標 org.bluestemsoftware.open.maven.plugin:launch4j-插件:1.5.0.0:launch4j (默認CLI)項目進口商:參數 'headerType', 'JRE' 爲目標 org.bluestemsoftware.open.maven.plugin:launch4j-插件:1.5.0.0:launch4j 缺失或無效的 - > [求助1]

也許我只是發動假目標...

Drejc!
+0

如何嘗試[this](https://github.com/vorburger/launch4j-maven-plugin)插件,這似乎是更新的? – Raghuram 2012-03-22 13:07:55

+0

vorburger插件看起來很有希望,但是應該執行哪個目標? – Drejc 2012-03-22 13:53:28

+0

執行mvn install我得到:缺少必需的類:com.akathist.maven.plugins.launch4j.Launch4jMojo失敗。這在vorburger演示應用程序中。 – Drejc 2012-03-22 14:21:13

回答

0

Drejc!

我可以生成一個與您的配置非常相似的.exe文件。下面我整個POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>test</groupId> 
    <artifactId>test</artifactId> 
    <packaging>jar</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>test</name> 

    <properties> 
     <mainClass>foo.App</mainClass> 
    </properties> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>1.4</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one --> 
        <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar --> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>com.akathist.maven.plugins.launch4j</groupId> 
       <artifactId>launch4j-maven-plugin</artifactId> 
       <executions> 
        <!-- Command-line exe --> 
        <execution> 
         <id>l4j-cli</id> 
         <phase>package</phase> 
         <goals> 
          <goal>launch4j</goal> 
         </goals> 
         <configuration> 
          <headerType>console</headerType> 
          <outfile>target/importer.exe</outfile> 
          <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above --> 
          <classPath> 
           <mainClass>${mainClass}</mainClass> 
          </classPath> 
          <jre> 
           <minVersion>1.5.0</minVersion> 
           <initialHeapSize>128</initialHeapSize> 
           <maxHeapSize>1024</maxHeapSize> 
          </jre> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>LATEST</version> 
     </dependency> 
    </dependencies> 

</project> 

我改變了插件的groupId和artifactId的到vorburger的一個,但alakai的版本應該工作了。確保:

  1. 您配置正確mainClass
  2. 你至少有一個依賴聲明(我曾在過去的一些麻煩,一些「非常小」的假象/零依賴構件)
  3. 你可以從回購

我只是測試這個POM用簡單的Maven原型下載插件,所以我看不出有什麼理由不工作您的計算機上。如果您有任何問題,請在此處詢問。

要生成.exe文件,我需要在終端上運行'mvn clean package',或者在Eclipse中,右鍵單擊您的項目'Run as ...'>'Maven build ...'並在目標文本框中輸入'clean package'。

相關問題