jar包打包成exe⽰例(基于maven项⽬)jar包打包成exe⽰例(基于maven项⽬)
说明
针对基于maven的Java项⽬,通常会打包成jar,
如果要把jar⽂件包装成exe⽂件,仅需要在l配置⽂件中增加⼀个插件即可
这⾥我们⽤,
还有其他的⽅式使⽤⽅式,这⾥只⽰范⼀下maven项⽬的使⽤
环境
jdk1.8
maven 3.5.2
Main⽅法
逻辑很简单,就是如果命令⾏有参数,则打印命令⾏的第⼀个参数,
⽆参数则打印“Hell World!”。
package com.hui;
/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
if (null != args && args.length > 0) {
System.out.println(args[0]);
} else {
System.out.println("Hello World!");
}
}
}
仅需要在build环节加⼊以下插件
<build>
<plugins>
<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>console</headerType>
<outfile></outfile>
<jar>target/java2exe-1.0-SNAPSHOT.jar</jar>
<errTitle>encc</errTitle>
<classPath>
<mainClass>com.hui.App</mainClass>
<addDependencies>false</addDependencies>
<preCp>anything</preCp>
</classPath>
<jre>
<minVersion>1.5.0</minVersion>
</jre>
<versionInfo>
<fileVersion>1.2.3.4</fileVersion>
<txtFileVersion>txt file version?</txtFileVersion>
<fileDescription>a description</fileDescription>
<copyright>my copyright</copyright>
<productVersion>4.3.2.1</productVersion>
<txtProductVersion>txt product version</txtProductVersion>
<productName>E-N-C-C</productName>
<internalName>ccne</internalName>
<originalFilename&</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
maven打包本地jar包<goals><goal>single</goal></goals>
<configuration>
<descriptors>
<descriptor&l</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
同时在项⽬根⽬录新建⼀个l⽂件
<assembly xmlns="/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/plugins/maven-assembly-plugin/assembly/1.1.2 /xsd/assembly-1.1.2.xsd"> <id>cdc-upgrade</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.exe</include>
</includes>
</fileSet>
</fileSets>
</assembly>
打包
执⾏
mvn clean package
打包以后,可以看到项⽬target⽬录下⽣成了 这个⽂件
在所在的⽬录下执⾏
encc aaa
输出结果
aaa
完整源码
参考⽂档
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论