maven生成exe文件

来源:互联网 发布:windows网络编程模型 编辑:程序博客网 时间:2024/05/02 02:22

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><transformerimplementation="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



0 0