Maven Launch4j Plugin InaccessibleObject // 将 JVM 参数添加到 POM

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

首先:请温柔点,我对此很陌生。

我有一个java应用程序,它是连接到wildfly实例的客户端。从 IDE 运行它是可行的。现在我想使用 akathist-launch4j-maven-plugin 和 maven-shade-plugin 将客户端包装到 .EXE。我使用它们而不是 jpackage 因为我不需要安装程序,而是一个普通的 exe 来运行程序。包装工作并运行,直到它尝试调用 java.util.AbstractMap()。

错误信息:

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected java.util.AbstractMap() accessible: module java.base does not "opens java.util" to unnamed module @7e32c033

来自https://stackoverflow.com/a/41265267/21859971我收集到如果我将“--add-opens java.base/java.lang=ALL-UNNAMED”传递给jvm,它就会起作用。

添加了排除过滤器,因为之前它会遇到阴影罐内的签名罐子的问题。

现在的问题是: a) 这是正确的做法吗?

b)如果是这样,我如何修改 pom 以包含此参数?

Pom 插件摘录:

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.4.1</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <filters>
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                    </excludes>
                </filter>
            </filters>              
            <shadedArtifactAttached>true</shadedArtifactAttached>
            <shadedClassifierName>shaded</shadedClassifierName>
            <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <mainClass>de/cni/client/gui/pages/main/StartApplication</mainClass>                        
                </transformer>
            </transformers>
        </configuration>
    </plugin>                                
    <plugin>
        <groupId>com.akathist.maven.plugins.launch4j</groupId>
        <artifactId>launch4j-maven-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
            <execution>
                <id>l4j-clui</id>
                <phase>package</phase>
                <goals>
                    <goal>launch4j</goal>
                </goals>
                <configuration>
                    <headerType>console</headerType>
                    <jar>${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar</jar>
                    <outfile>${project.build.directory}/app-client.exe</outfile>
                    <classPath>
                        <mainClass>[..]/client/gui/pages/main/StartApplication</mainClass>
                        <preCp>anything</preCp>
                    </classPath>                                
                  <jre>
                    <path>${java.home}/bin</path>
                    <minVersion>17.0.2</minVersion>
                    <maxVersion></maxVersion>
                    <requiresJdk>true</requiresJdk>
                    <requires64Bit>true</requires64Bit>     
                  </jre>
                </configuration>
            </execution>
        </executions>
    </plugin>

编辑: 按照传统,发布此文一小时后,我尝试了之前做过的一些操作,现在它起作用了。 我补充道:

                    <opts>
                        <opt>--add-opens java.base/java.util=ALL-UNNAMED</opt>
                        <opt>--add-opens java.base/java.util.concurrent=ALL-UNNAMED</opt>
                    </opts>

到 launch4j 插件,现在它正在运行。

我不会把这个作为答案,因为我相当确定有更好(正确)的方法来解决这个问题。

java maven maven-shade-plugin launch4j
1个回答
0
投票

根据 Warren P 的要求,以下是 pom.xml 的摘录。希望有帮助。

<build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
                    <plugin>
                    <groupId>com.akathist.maven.plugins.launch4j</groupId>
                    <artifactId>launch4j-maven-plugin</artifactId>
                    <version>2.5.0</version>
                    <executions>
                        <execution>
                            <id>l4j-clui</id>
                            <phase>package</phase>
                            <goals>
                                <goal>launch4j</goal>
                            </goals>
                            <configuration>
                                <dontWrapJar>false</dontWrapJar>                                
                                <headerType>console</headerType>
                                <jar>${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar</jar>
                                <outfile>${project.build.directory}/client.exe</outfile>
                                <classPath>
                                    <mainClass>[snip]/StartApplication</mainClass>
                                    <addDependencies>true</addDependencies>
                                </classPath>                                
                              <jre>
                                <path>${java.home}/bin</path>
                                <minVersion>17.0.2</minVersion>
                                <maxVersion></maxVersion>
                                <requiresJdk>true</requiresJdk>
                                <requires64Bit>true</requires64Bit>     
                                <opts>
                                    <opt>--add-opens java.base/java.util=ALL-UNNAMED</opt>
                                    <opt>--add-opens java.base/java.lang=ALL-UNNAMED</opt>
                                    <opt>--add-opens java.base/java.util.concurrent=ALL-UNNAMED</opt>
                                    <opt>-Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS</opt>
                                </opts>
                              </jre>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.