首页 > 解决方案 > Maven 不执行 Launch4j 插件

问题描述

我正在尝试exe使用 Launch4j 构建文件,但实际上 Maven 似乎没有检测到我将插件绑定到package阶段。

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<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.project1616</groupId>
    <artifactId>Project16x16</artifactId>
    <version>1.0.0</version>

    <name>Project16x16</name>
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <repositories>
        <repository>
            <id>repo</id>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>file://${project.basedir}/repo</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>core</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>DM</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>gicentreUtils</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx-swt</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.base</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.controls</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.fxml</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.graphics</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.media</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.swing</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>local</groupId>
            <artifactId>javafx.web</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>13</version>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>org.project16x16.sidescroller.SideScroller</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.akathist.maven.plugins.launch4j</groupId>
                    <artifactId>launch4j-maven-plugin</artifactId>
                    <version>1.7.25</version>
                    <executions>
                        <execution>
                            <id>l4j-clui</id>
                            <phase>package</phase>
                            <goals>
                                <goal>launch4j</goal>
                            </goals>
                            <configuration>
                                <headerType>gui</headerType>
                                <jar>${project.build.directory}/Project16x16-1.0.0-jar-with-dependencies.jar</jar>
                                <outfile>${project.build.directory}/${project.artifactId}.exe</outfile>
                                <downloadUrl>http://java.com/download</downloadUrl>
                                <pluginArtifacts>${plugin.artifacts}</pluginArtifacts>
                                <jre>
                                    <path>C:\Program Files\Java\jdk-12.0.2</path>
                                    <bundledJre64Bit>false</bundledJre64Bit>
                                    <bundledJreAsFallback>false</bundledJreAsFallback>
                                    <minVersion></minVersion>
                                    <maxVersion></maxVersion>
                                    <jdkPreference>preferJre</jdkPreference>
                                    <runtimeBits>64/32</runtimeBits>
                                </jre>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

这是我运行命令时得到的日志mvn package

[INFO]
[INFO] --------------------< org.project1616:Project16x16 >--------------------
[INFO] Building Project16x16 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ Project16x16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 57 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Project16x16 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ Project16x16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\myDir\Project16x16\source\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Project16x16 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\myDir\Project16x16\source\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ Project16x16 ---
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ Project16x16 ---
[INFO] Building jar: C:\myDir\Project16x16\source\target\Project16x16-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.193 s
[INFO] Finished at: 2019-10-08T20:46:06+02:00
[INFO] ------------------------------------------------------------------------

如您所见,该插件从未执行过。在我的pom.xml我已经解除了所有阶段的束缚,但它似乎什么也没做。

任何帮助表示赞赏!谢谢

标签: mavenmaven-3

解决方案


下面声明的所有插件pluginManagement都只是配置,旨在供当前或子项目使用。plugins除非您在标签内声明它们,否则它们不会被执行。

话虽如此,您仍然需要在plugins标签内声明插件,如下所示。

<?xml version="1.0" encoding="UTF-8"?>

<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>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                ...
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

请注意,没有launch4j-maven-plugin定义 for 的版本,因为它将继承自pluginManagement.


推荐阅读