maven生成exe文件

1、编写源代码

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. package org.pzy.exe_test;  
  2.   
  3. import javax.swing.JColorChooser;  
  4. import javax.swing.JDialog;  
  5.   
  6. /** 
  7.  * Hello world! 
  8.  *  
  9.  */  
  10. public class Main extends JDialog {  
  11.     private static final long serialVersionUID = 1L;  
  12.     private final JColorChooser cc;  
  13.   
  14.     public Main() {  
  15.         setSize(800600);  
  16.         setTitle("hasCode.com launch4j Maven Tutorial");  
  17.         cc = new JColorChooser();  
  18.         add(cc);  
  19.         setDefaultCloseOperation(DISPOSE_ON_CLOSE);  
  20.         setVisible(true);  
  21.     }  
  22.   
  23.     public static void main(final String[] args) {  
  24.         new Main();  
  25.     }  
  26.   
  27. }  

2、配置pom

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.   
  5.     <groupId>org.pzy</groupId>  
  6.     <artifactId>exe-test</artifactId>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <packaging>jar</packaging>  
  9.   
  10.     <name>exe-test</name>  
  11.     <url>http://maven.apache.org</url>  
  12.   
  13.     <properties>  
  14.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  15.     </properties>  
  16.     <build>  
  17.         <plugins>  
  18.             <plugin>  
  19.                 <groupId>org.apache.maven.plugins</groupId>  
  20.                 <artifactId>maven-compiler-plugin</artifactId>  
  21.                 <configuration>  
  22.                     <source>1.7</source>  
  23.                     <target>1.7</target>  
  24.                 </configuration>  
  25.             </plugin>  
  26.             <plugin>  
  27.                 <groupId>org.apache.maven.plugins</groupId>  
  28.                 <artifactId>maven-shade-plugin</artifactId>  
  29.                 <executions>  
  30.                     <execution>  
  31.                         <phase>package</phase>  
  32.                         <goals>  
  33.                             <goal>shade</goal>  
  34.                         </goals>  
  35.                     </execution>  
  36.                 </executions>  
  37.                 <configuration>  
  38.                     <shadedArtifactAttached>true</shadedArtifactAttached>  
  39.                     <shadedClassifierName>shaded</shadedClassifierName>  
  40.                     <transformers>  
  41.                         <transformer  
  42.                             implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  43.                             <mainClass>org.pzy.exe_test.Main</mainClass>  
  44.                         </transformer>  
  45.                     </transformers>  
  46.                 </configuration>  
  47.             </plugin>  
  48.             <plugin>  
  49.                 <groupId>com.akathist.maven.plugins.launch4j</groupId>  
  50.                 <artifactId>launch4j-maven-plugin</artifactId>  
  51.                 <executions>  
  52.                     <execution>  
  53.                         <id>l4j-clui</id>  
  54.                         <phase>package</phase>  
  55.                         <goals>  
  56.                             <goal>launch4j</goal>  
  57.                         </goals>  
  58.                         <configuration>  
  59.                             <headerType>gui</headerType>  
  60.                             <jar>${project.build.directory}/${artifactId}-${version}-shaded.jar</jar>  
  61.                             <outfile>${project.build.directory}/hasCode.exe</outfile>  
  62.                             <downloadUrl>http://java.com/download</downloadUrl>  
  63.                             <classPath>  
  64.                                 <mainClass>org.pzy.exe_test.Main</mainClass>  
  65.                                 <preCp>anything</preCp>  
  66.                             </classPath>  
  67.                             <icon>src/resources/0.ico</icon>  
  68.                             <jre>  
  69.                                 <minVersion>1.7.0</minVersion>  
  70.                                 <jdkPreference>preferJre</jdkPreference>  
  71.                             </jre>  
  72.                             <versionInfo>  
  73.                                 <fileVersion>1.0.0.0</fileVersion>  
  74.                                 <txtFileVersion>${project.version}</txtFileVersion>  
  75.                                 <fileDescription>${project.name}</fileDescription>  
  76.                                 <copyright>2012 hasCode.com</copyright>  
  77.                                 <productVersion>1.0.0.0</productVersion>  
  78.                                 <txtProductVersion>1.0.0.0</txtProductVersion>  
  79.                                 <productName>${project.name}</productName>  
  80.                                 <companyName>hasCode.com</companyName>  
  81.                                 <internalName>hasCode</internalName>  
  82.                                 <originalFilename>hasCode.exe</originalFilename>  
  83.                             </versionInfo>  
  84.                         </configuration>  
  85.                     </execution>  
  86.                 </executions>  
  87.             </plugin>  
  88.         </plugins>  
  89.     </build>  
  90. </project>  

3、执行maven命令

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. 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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值