1、编写源代码
- package org.pzy.exe_test;
- import javax.swing.JColorChooser;
- import javax.swing.JDialog;
- /**
- * Hello world!
- *
- */
- public class Main extends JDialog {
- private static final long serialVersionUID = 1L;
- private final JColorChooser cc;
- public Main() {
- setSize(800, 600);
- setTitle("hasCode.com launch4j Maven Tutorial");
- cc = new JColorChooser();
- add(cc);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- setVisible(true);
- }
- public static void main(final String[] args) {
- new Main();
- }
- }
2、配置pom
- <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>org.pzy</groupId>
- <artifactId>exe-test</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>exe-test</name>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <shadedArtifactAttached>true</shadedArtifactAttached>
- <shadedClassifierName>shaded</shadedClassifierName>
- <transformers>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>org.pzy.exe_test.Main</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}-${version}-shaded.jar</jar>
- <outfile>${project.build.directory}/hasCode.exe</outfile>
- <downloadUrl>http://java.com/download</downloadUrl>
- <classPath>
- <mainClass>org.pzy.exe_test.Main</mainClass>
- <preCp>anything</preCp>
- </classPath>
- <icon>src/resources/0.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>2012 hasCode.com</copyright>
- <productVersion>1.0.0.0</productVersion>
- <txtProductVersion>1.0.0.0</txtProductVersion>
- <productName>${project.name}</productName>
- <companyName>hasCode.com</companyName>
- <internalName>hasCode</internalName>
- <originalFilename>hasCode.exe</originalFilename>
- </versionInfo>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </project>
3、执行maven命令
- package
<headerType>gui</headerType> 生成gui程序
<headerType>console</headerType> 生成控制台程序
<jre>
<path>bin/jre</path><span style="white-space:pre"> </span>//这一段指定绑定jre的路径
<bundledJre64Bit>true</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion></minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>