2012-02-14 64 views
1

我在同一個文件夾內有兩個maven項目。一個依賴於另一個,即另一個依賴於它。 現在我想使用maven遮罩插件和launch4j,但它似乎很複雜。Maven Shade Plugin + Launch4j

有人可以給我一步一步解釋我的情況嗎?

所以我有2個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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org</groupId> 
    <artifactId>some artifact</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <encoding>UTF-8</encoding> 
       <target>1.5</target> 
       <source>1.5</source> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.3.1</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <!-- This bit sets the main class for the executable jar as you otherwise --> 
          <!-- would with the assembly plugin          --> 
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <manifestEntries> 
            <Main-Class>my_main class from project1</Main-Class> 
           </manifestEntries> 
          </transformer> 
          <!-- This bit merges the various GeoTools META-INF/services files   --> 
          <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
<modules> 
    <module>project1</module> 
    <module>project2</module> 
</modules> 
</project> 

,然後我得到以下錯誤: 在項目2:無法創建陰影的神器,項目主神器不存在。

+0

你有兩個項目在同一個文件夾,或者你有一個父項目內有兩個模塊?你能提供關於你的結構的更多細節嗎? – BrunoJCM 2012-05-21 18:32:00

回答

0

您應該在每個模塊上配置可執行文件。在父POM(這似乎你發佈的POM是什麼),沒有什麼可以做的。你應該去每個模塊的POM你想有一個.exe和做什麼,我張貼在這個問題:Trying to integrate Launch4j in a Maven project using Alakai plugin

我也回答了有關.exe文件這個其他的問題,但產生一個控制檯.exe文件(無GUI):Wrapping a java command line application with launch4j and maven 。這一個有一個完整的POM和更新。

父項目和poms主要用於聚合彼此依賴的模塊的構建。所以,就你的情況而言,考慮到project2取決於project1,你應該對project2的pom進行設置並按照前面提到的方式進行設置。

1

我一般同意BrunoJCM,只是想補充說,你已經放在父pom的規則只適用於父pom,它們不是按照你的意圖「繼承」。由於家長pom不生產任何罐子,所有你的調音都是無用的。

您需要的是始終激活的配置文件。而配置文件是從父pom繼承!

我複製粘貼你的規則,我希望他們的工作爲的是:

<profiles> 
    <profile> 
     <id>run-shade</id> 

     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 

     <build> 
      <plugins> 
       <plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <configuration> 
         <encoding>UTF-8</encoding> 
         <target>1.5</target> 
         <source>1.5</source> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-shade-plugin</artifactId> 
        <version>1.3.1</version> 
        <executions> 
         <execution> 
          <phase>package</phase> 
          <goals> 
           <goal>shade</goal> 
          </goals> 
          <configuration> 
           <transformers> 
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
             <manifestEntries> 
              <Main-Class>my_main class from project1</Main-Class> 
             </manifestEntries> 
            </transformer> 
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 
           </transformers> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

您還需要自定義每個子模塊您的個人資料(如主類)。

<Main-Class>${main.class}</Main-Class> 

然後定義一個屬性每個模塊POM:您可以通過將一個變量在你的父POM的個人資料做

<properties> 
    <main.class>org.company.project.Main</main.class> 
</properties> 
0

嘗試添加排除節點到您的陰影配置來排除項目​​的主要僞像。在這裏看到類似的問題:Project-Main-Artifact-Does-Not-Exist

     <configuration> 
          <transformers> 
           <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <manifestEntries> 
             <Main-Class>my_main class from project1</Main-Class> 
            </manifestEntries> 
           </transformer> 
           <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 
          </transformers> 
          <excludes> 
           <exclude>${project.groupId}:${project.artifactId}</exclude> 
          </excludes> 
         </configuration>