Launch4J 插件创建了一个 EXE(连同 JAR),但 EXE 在 Spring 引导中找不到主类 [英] Launch4J Plugin creates an EXE (along with JAR) but EXE cannot find main class in Spring boot
问题描述
在 Launch4J 插件的帮助下,我编写了一个插件来为我的项目创建 EXE 和 JAR.但是,在执行 EXE 文件时,出现错误 -
I wrote a plugin to create an EXE and JAR for my project with the help of Launch4J plugin. However, on executing the EXE file, I get the error -
Error: Could not find or load main class
但是,我通过给 java -jar app.jar
运行 JAR,它运行完美.
However, I run the JAR by giving java -jar app.jar
, it runs perfectly.
这是我的插件部分
<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 存在于我的目标文件夹中.但是我无法执行它,因为它说找不到主类(尽管在插件详细信息中添加了它)
The EXE is present in my target folder. But I cannot execute it as it says Main Class not found (despite adding it in the plugin details)
推荐答案
尝试使用以下命令为任何 Maven 项目调整 Maven 构建.
Try to tun the maven build using the following command for any maven project.
mvn clean package 或 mvn clean install
mvn clean package or mvn clean install
关于 Launch4j,您必须运行以下命令.
With regard to Launch4j, you have to run the following command.
mvn 清洁包
有关 Launch4j 的更多详细信息,您可以查看以下链接.https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc
For more details on Launch4j, you can check below the link. https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc
但是在这个项目中,我看到你正在使用 spring boot.如果我的理解是对的,你想用spring boot创建一个exe文件.如果是这种情况.
But in this project, I see you are using spring boot. If my understanding is correct, you want to create an exe file out of spring boot. If this is the case.
您可以尝试将以下更改用于 launch4j 并检查.
Can you try to use the below changes for launch4j and check.
<classPath>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
<addDependencies>true</addDependencies>
<preCp>anything</preCp>
</classPath>
这篇关于Launch4J 插件创建了一个 EXE(连同 JAR),但 EXE 在 Spring 引导中找不到主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!