J'ai écrit un plugin pour créer un fichier EXE et JAR pour mon projet avec l'aide de plug-in Launch4j. Cependant, sur l'exécution du fichier EXE, je reçois l'erreur -
Error: Could not find or load main class
Cependant, je lance le JAR en donnant java -jar app.jar
, il fonctionne parfaitement.
Ceci est ma section plug-in
<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>
Le EXE est présent dans mon dossier cible. Mais je ne peux pas l'exécuter comme il est dit la classe principale ne se trouve pas (malgré l'ajouter dans les détails du plugin)
Essayez de tun la build Maven en utilisant la commande suivante pour tout projet Maven.
mvn clean package ou mvn installation propre
En ce qui concerne Launch4j, vous devez exécuter la commande suivante.
package mvn clean
Pour plus de détails sur Launch4j, vous pouvez vérifier le lien ci - dessous. https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc
Mais dans ce projet, je vois que vous utilisez le démarrage de printemps. Si je comprends bien, vous voulez créer un fichier exe de démarrage du printemps. Si c'est le cas.
Pouvez-vous essayer d'utiliser les changements ci-dessous pour launch4j et vérification.
<classPath>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
<addDependencies>true</addDependencies>
<preCp>anything</preCp>
</classPath>