使用 launch4j 和 maven 创建 exe
Create exe with launch4j with maven
我想用 launch4j 将我的 jar 包装到一个 exe 文件中。这是我的 pom.xml:
<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>de.thz.cameracontrol</groupId>
<artifactId>Kamerasteuerung</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>name</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<version.maven.compiler>2.3.2</version.maven.compiler>
<version.maven.site>3.3</version.maven.site>
<version.sonar>4.3</version.sonar>
<artifact.id>Kamerasteuerung</artifact.id>
</properties>
<profiles>
<!-- profiles for repositories and distribution management -->
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven.compiler}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${version.maven.site}</version>
</plugin>
<!-- LAUNCH4J -->
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>console</headerType>
<jar>target/Kamerasteuerung-0.0.3-SNAPSHOT-jar-with-dependencies.jar</jar>
<outfile>target/CameraControl.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>de.thz.cameracontrol.server.Server</mainClass>
</classPath>
<jre>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>C</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<internalName>AppName</internalName>
<originalFilename>CameraControl.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>de.thz.cameracontrol.server.Server</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- LAUNCH4J ENDE -->
</plugins>
</pluginManagement>
</build>
<dependencies>
...
</dependencies>
这是我的批次:
@echo off
call mvn -D skipTests clean assembly:attached
pause
我得到了一个正确的 jar 和我的依赖项,但我没有得到 exe 文件。还有别的事情要做吗? descriptor.xml 真的有必要吗?
虽然我没有正确检查你的pom。因为它正在生产正确的罐子,所以我认为它很好。
你试过 mvn package 了吗?
我已经使用了你的例子,谢谢它很有帮助。我第一次 运行 时,它抛出了一个错误,告诉我罐子不可见。因此,我将 launch4j 阶段更改为安装,以确保它在程序包上的程序集插件之后运行。
我想用 launch4j 将我的 jar 包装到一个 exe 文件中。这是我的 pom.xml:
<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>de.thz.cameracontrol</groupId>
<artifactId>Kamerasteuerung</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>name</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<version.maven.compiler>2.3.2</version.maven.compiler>
<version.maven.site>3.3</version.maven.site>
<version.sonar>4.3</version.sonar>
<artifact.id>Kamerasteuerung</artifact.id>
</properties>
<profiles>
<!-- profiles for repositories and distribution management -->
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven.compiler}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${version.maven.site}</version>
</plugin>
<!-- LAUNCH4J -->
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>console</headerType>
<jar>target/Kamerasteuerung-0.0.3-SNAPSHOT-jar-with-dependencies.jar</jar>
<outfile>target/CameraControl.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>de.thz.cameracontrol.server.Server</mainClass>
</classPath>
<jre>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>C</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<internalName>AppName</internalName>
<originalFilename>CameraControl.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>de.thz.cameracontrol.server.Server</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- LAUNCH4J ENDE -->
</plugins>
</pluginManagement>
</build>
<dependencies>
...
</dependencies>
这是我的批次:
@echo off
call mvn -D skipTests clean assembly:attached
pause
我得到了一个正确的 jar 和我的依赖项,但我没有得到 exe 文件。还有别的事情要做吗? descriptor.xml 真的有必要吗?
虽然我没有正确检查你的pom。因为它正在生产正确的罐子,所以我认为它很好。 你试过 mvn package 了吗?
我已经使用了你的例子,谢谢它很有帮助。我第一次 运行 时,它抛出了一个错误,告诉我罐子不可见。因此,我将 launch4j 阶段更改为安装,以确保它在程序包上的程序集插件之后运行。