Launch4J 插件创建一个 EXE(以及 JAR),但 EXE 在 Spring boot 中找不到主类

2023-12-22

我编写了一个插件,在 Launch4J 插件的帮助下为我的项目创建 EXE 和 JAR。但是,在执行 EXE 文件时,我收到错误 -

Error: Could not find or load main class

但是,我通过提供来运行 JARjava -jar app.jar,它运行完美。

这是我的插件部分

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.mycompany.tool.orchestrator.command.CommandHandler</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.7.16</version>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <outfile>target/apidast.exe</outfile>
                            <jar>${project.build.directory}/${artifactId}-${version}.jar</jar>
                            <errTitle>encc</errTitle>
                            <classPath>
                                <mainClass>com.mycompany.tool.orchestrator.command.CommandHandler</mainClass>
                                <!--Not sure what the next 2 lines are for -->
                                <addDependencies>true</addDependencies>
                                <preCp>anything</preCp>
                            </classPath>
                            <jre>
                                <minVersion>1.8.0_212</minVersion>
                                <!--Not sure what these opts are for -->
                                <opts>
                                    <opt>-Djava.endorsed.dirs=./endorsed</opt>
                                </opts>
                            </jre>
                            <versionInfo>
                                <fileVersion>0.0.1.0</fileVersion>
                                <txtFileVersion>0.0.1.0</txtFileVersion>
                                <fileDescription>${project.name}</fileDescription>
                                <copyright>My Company.</copyright>
                                <productVersion>0.0.1.0</productVersion>
                                <txtProductVersion>${version}</txtProductVersion>
                                <productName>${project.name}</productName>
                                <originalFilename>apidast.exe</originalFilename>
                                <!-- internalName is mandatory -->
                                <internalName>apidast</internalName>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

EXE 存在于我的目标文件夹中。但我无法执行它,因为它说找不到主类(尽管在插件详细信息中添加了它)


尝试对任何 Maven 项目使用以下命令运行 Maven 构建。

mvn clean package 或 mvn clean install

对于Launch4j,您必须运行以下命令。

mvn清理包

有关 Launch4j 的更多详细信息,您可以查看下面的链接。https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc

但在这个项目中,我看到你正在使用 spring boot。如果我的理解是正确的,您想在 Spring Boot 之外创建一个 exe 文件。如果是这样的话。

您可以尝试对 launch4j 使用以下更改并检查。

<classPath>                    
   <mainClass>org.springframework.boot.loader.JarLauncher</mainClass>                                
   <addDependencies>true</addDependencies>
   <preCp>anything</preCp>
</classPath>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Launch4J 插件创建一个 EXE(以及 JAR),但 EXE 在 Spring boot 中找不到主类 的相关文章

随机推荐