2012-02-14 59 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>