将 maven 与 jar 中的 launch4j 构建窗口 exe 一起使用时,“无法访问属性的默认字段”

问题描述 投票:0回答:1

我用java 17编写了一个编辑excel文件的cmd程序。然后,我想将其构建为windows可执行exe文件。通过阅读下面的文章,尝试使用maven插件shade和launch4j构建,但在launch4j中不断显示“无法访问属性的默认字段”错误。想知道为什么吗?

这是我参考的帖子

<?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.example</groupId>
    <artifactId>combine_excel</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>combine_excel</name>
    <url>http://maven.apache.org</url>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.7.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>shaded</shadedClassifierName>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>org.example.Main</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.5.1</version>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <jar>target/${artifactId}-${version}-shaded.jar</jar>
                            <outfile>target/combine_excel.exe</outfile>
<!--                            <downloadUrl>http://java.com/download</downloadUrl>-->
                            <classPath>
                                <mainClass>org.example.Main</mainClass>
                                <preCp>anything</preCp>
                            </classPath>
<!--                            <icon>application.ico</icon>-->
                            <jre>
                                <minVersion>1.6.0</minVersion>
                                <jdkPreference>preferJre</jdkPreference>
                            </jre>
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>${project.version}</txtFileVersion>
                                <fileDescription>${project.name}</fileDescription>
                                <copyright>2012 combine_excel.com</copyright>
                                <productVersion>1.0.0.0</productVersion>
                                <txtProductVersion>1.0.0.0</txtProductVersion>
                                <productName>${project.name}</productName>
                                <companyName>combine_excel.com</companyName>
                                <internalName>combine_excel</internalName>
                                <originalFilename>combine_excel.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>AsposeJavaAPI</id>
            <name>Aspose Java API</name>
            <url>https://repository.aspose.com/repo/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-cells</artifactId>
            <version>21.6</version>
        </dependency>
    </dependencies>
</project>

这是错误日志。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.091 s
[INFO] Finished at: 2023-09-26T22:21:33+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.akathist.maven.plugins.launch4j:launch4j-maven-plugin:1.5.1:launch4j (l4j-clui) on project combine_excel: Execution l4j-clui of goal com.akathist.maven.plugins.launch4j:launch4j-maven-plugin:1.5.1:launch4j failed: An API incompatibility was encountered while executing com.akathist.maven.plugins.launch4j:launch4j-maven-plugin:1.5.1:launch4j: java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.akathist.maven.plugins.launch4j:launch4j-maven-plugin:1.5.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/gary6/.m2/repository/com/akathist/maven/plugins/launch4j/launch4j-maven-plugin/1.5.1/launch4j-maven-plugin-1.5.1.jar
[ERROR] urls[1] = file:/C:/Users/gary6/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.4/plexus-component-annotations-1.5.4.jar
[ERROR] urls[2] = file:/C:/Users/gary6/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[3] = file:/C:/Users/gary6/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[4] = file:/C:/Users/gary6/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
[ERROR] urls[5] = file:/C:/Users/gary6/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[6] = file:/C:/Users/gary6/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[7] = file:/C:/Users/gary6/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[8] = file:/C:/Users/gary6/.m2/repository/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar
[ERROR] urls[9] = file:/C:/Users/gary6/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
[ERROR] urls[10] = file:/C:/Users/gary6/.m2/repository/org/apache/ant/ant/1.7.0/ant-1.7.0.jar
[ERROR] urls[11] = file:/C:/Users/gary6/.m2/repository/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar
[ERROR] urls[12] = file:/C:/Users/gary6/.m2/repository/foxtrot/foxtrot/2.0/foxtrot-2.0.jar
[ERROR] urls[13] = file:/C:/Users/gary6/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar
[ERROR] urls[14] = file:/C:/Users/gary6/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

我认为 launch4j 配置值一开始是错误的。我添加了 标签内引用的所有缺失参数并评论了图标照片,但它没有任何作用。此外,我尝试过用战争构建但失败了。

java maven build launch4j
1个回答
0
投票

将 launch4j-maven-plugin 更新到最新版本 2.4.1,将 maven-shade-plugin 更新到 3.5.1,这是 2012 年的旧版本,可能与 java 17 不兼容

© www.soinside.com 2019 - 2024. All rights reserved.