Maven Shade插件+ Launch4j

时间:2012-02-14 22:49:25

标签: maven plugins maven-shade-plugin launch4j

我在同一个文件夹中有两个maven项目。一个依赖于其他,即另一个依赖于它。 现在我想使用maven shade插件和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>

然后我收到以下错误: 在project2中:无法创建着色工件,项目主工件不存在。

3 个答案:

答案 0 :(得分: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>

您还需要自定义每个子模块的配置文件(例如主类)。您可以通过在父pom配置文件中放置一个变量来实现此目的:

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

然后在每个模块pom 中定义一个属性:

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

答案 1 :(得分:0)

您应该在每个模块上配置可执行文件。在父母pom(这似乎是你发布的pom)中,你无能为力。你应该去你想要一个.exe的每个模块的pom,并做我在这个问题上发布的内容: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进行设置并按照我之前提到的那样进行设置。

答案 2 :(得分: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>
相关问题