maven 打包exe可执行文件

使用java编写的桌面程序,因分发给window平台用户时需要预先安装jdk才能运行,不方便,而使用本文说的launch4j可以让maven项目直接打包成exe,无需安装,双击运行。

示例pom(仅截取了build标签部分):


<build >
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>UTF-8</encoding>
					<compilerArguments>
						<extdirs>${basedir}/lib</extdirs>
					</compilerArguments>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<executions>
					<execution>
						<id>${artifactId}_${maven.build.timestamp}</id>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<finalName>${artifactId}_${maven.build.timestamp}</finalName>
						</configuration>
					</execution>
				</executions>
				<configuration>
					<shadedArtifactAttached>true</shadedArtifactAttached>
					<shadedClassifierName>shaded</shadedClassifierName>
					<transformers>
						<transformer
								implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
							<mainClass>com.ydj.zhuaqu.ali1688.ui.start.Bootstrap</mainClass>
						</transformer>
					</transformers>
				</configuration>
			</plugin>
			<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>gui</headerType>
							<jar>${project.build.directory}/${artifactId}_${maven.build.timestamp}.jar</jar>
							<outfile>${project.build.directory}/${artifactId}_${maven.build.timestamp}.exe</outfile>
							<downloadUrl>http://java.com/download</downloadUrl>
							<classPath>
								<mainClass>com.ydj.zhuaqu.ali1688.ui.start.Bootstrap</mainClass>
								<preCp>anything</preCp>
							</classPath>
							<icon>src/main/resources/logo.ico</icon>
							<jre>
								<minVersion>1.7.0</minVersion>
								<jdkPreference>preferJre</jdkPreference>
							</jre>
							<versionInfo>
								<fileVersion>1.0.0.0</fileVersion>
								<txtFileVersion>${project.version}</txtFileVersion>
								<fileDescription>${project.name}</fileDescription>
								<copyright>2018 www.renmaitong.com</copyright>
								<productVersion>1.0.0.0</productVersion>
								<txtProductVersion>1.0.0.0</txtProductVersion>
								<productName>${project.name}</productName>
								<companyName>www.renmaitong.com</companyName>
								<internalName>${artifactId}-${version}</internalName>
								<originalFilename>${artifactId}-${version}.exe</originalFilename>
							</versionInfo>
						</configuration>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>

(全文完)

(转载本站文章请注明作者和出处 maven 打包exe可执行文件