Maven 生成exe文件

Jar本身是可以运行的,但是Windows平台下更多人对exe情有独钟! Maven 的 Launch4j 插件应运而生。在Maven Shade 插件 或 Maven Assembly 插件的配合下,一键生成exe! 1.一个Java应用 这个。。。 2.Maven配置 Shade或Assembly插件将所有依赖的文件打包到一个单独可运行的 jar 文件,转换器会在 MANIFEST.MF 中增加 Main-Class 属性。 Launch4j自然是将其转成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>com.hascode.tutorial</groupid> <artifactid>launch4j-maven-sample</artifactid> <version>0.0.1</version> <name>hasCode Launch4j Maven Example</name> <properties> <project .build.sourceEncoding>UTF-8</project> </properties> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-shade-plugin</artifactid> <version>1.7.1</version> <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>com.hascode.tutorial.Main</mainclass> </transformer> </transformers> </configuration> </plugin> <plugin> <groupid>com.akathist.maven.plugins.launch4j</groupid> <artifactid>launch4j-maven-plugin</artifactid> <version>1.5.1</version> <executions> <execution> <id>l4j-clui</id> <phase>package</phase> <goals> <goal>launch4j</goal> </goals> <configuration> <headertype>gui</headertype> <jar>${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar</jar><!--project--> <outfile>${project.build.directory}/hasCode.exe</outfile> <downloadurl>http://java.com/download</downloadurl> <classpath> <mainclass>com.hascode.tutorial.Main</mainclass> <precp>anything</precp> </classpath> <icon>src/main/resources/icon/application.ico</icon> <jre> <minversion>1.6.0</minversion><!--x.x.x--> <jdkpreference>preferJre</jdkpreference> </jre> <versioninfo> <fileversion>1.0.0.0</fileversion><!--x.x.x.x--> <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命令 4.调试 Log4j 生成 launch4j.log日志,运行时添加参数“--l4j-debug”即可,如hasCode.exe --l4j-debug。 Via http://www.oschina.net/question/12_64286

你可能感兴趣的:(maven)