jar包打包成exe示例(基于maven项目)

说明

针对基于maven的Java项目,通常会打包成jar,

如果要把jar文件包装成exe文件,仅需要在pom.xml配置文件中增加一个插件即可

这里我们用launch4j

launch4j 还有其他的方式使用方式,这里只示范一下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!");
}
}
}

pom.xml 示例

仅需要在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>target/encc.exe</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>original.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

同时在项目根目录新建一个assembly.xml文件

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/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.exe这个文件

在encc.exe所在的目录下执行

encc aaa

输出结果

aaa

完整源码

代码

参考文档

Maven Launch4j Plugin

jar包打包成exe示例(基于maven项目)的更多相关文章

  1. java jar文件打包成exe(Launch4j使用说明)

    在日常的项目中需要把jar打包成exe.怎样快速的实现此功能.下面通过Launch4j的使用方法来介绍整个打包过程. 第一步:生成jar文件 第二部:使用Launch4j 图来描述过,简单明了.一切尽 ...

  2. 用exe4j将jar包转成.exe文件的教程

    标准版教程再这里 http://pan.baidu.com/s/1i3gn0Br 1.    下载安装exe4j文件,并把你的java文件生成jar格式的文件,在桌面新建一个文件夹,把jar文件放进去 ...

  3. class打包成exe方式

    首先运行dos命令 jar -cvf **.jar *.class 把所有文件打包成jar包 用解压器打开jar包 打开meta-inf文件夹 打开用记事本打开main.mf文件 增加语句Main-C ...

  4. Java项目打包成exe的详细教程

    Java项目打包成exe的详细教程 把Java项目打包成exe共分为以下两步: 1. 利用Eclipse先把Java项目先打成jar包 2. 利用exe4j工具把jar包转成exe 这里以Java项目 ...

  5. Java 精简Jre jar打包成exe

    #开始 最近几天都在忙一个事情,那就是尝试精简jre,我想不明白为什么甲骨文官方不出exe打包工具... 网络上精简jre的文章很多,但是原创的似乎没几个,绝大多数都是转发同一个博客, 这里借鉴了不少 ...

  6. JAVA程序打包成exe小程序的过程

    编程软件:myeclipse2014 打包exe软件:exe4j 1:在myeclipse2014新建java项目编写程序 2:打包成jar,分两种情况(有无外部依赖包) 无外部依赖包:点击项目--- ...

  7. Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer 关于Newtonsoft.Json,LINQ to JSON的一个小demo mysql循环插入数据、生成随机数及CONCAT函数 .NET记录-获取外网IP以及判断该IP是属于网通还是电信 Guid的生成和数据修整(去除空格和小写字符)

    Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer   Advanced Installer :Free for 30 da ...

  8. Java桌面程序打包成exe可执行文件

    前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...

  9. JAVA程序打包成exe文件详细图解

    我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: eclipse ...

随机推荐

  1. 以太坊客户端Geth命令用法

    命令用法 geth [选项] 命令 [命令选项] [参数…] 命令: account 管理账户attach 启动交互式JavaScript环境(连接到节点)bug 上报bug Issuesconsol ...

  2. [置顶] apt-get update 更新失败----如何清除破损而且陈旧的PPA仓库 (W: Failed to fetch http://ppa.launchpad.net/jonathonf/pyt)

    我使用sudo apt-get update之后,更新失败,遇到如下错误. W: Failed to fetch http://ppa.launchpad.net/jonathonf/python-3 ...

  3. 打开图片并显示在面板上demo

    import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...

  4. Oracle重建临时表空间

    [oracle@hd58 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Wed Jun 27 11:58:25  ...

  5. Metasploit对安卓手机的攻击

    首先要kali进行内网穿透,可参考http://www.cnblogs.com/sch01ar/p/7562954.html 首先生成一个apk木马 命令:msfvenom -p android/me ...

  6. 【Kettle】Java借助Kettle将Excel导入数据

    示例功能(仅供测试): 在JAVA项目中,将数据从Excel文件导入数据库中.实现该能有多种方法,而本例则是“不走寻常路”,尝试借助Kettle实现数据导入. 原理: Java中调用存储在Kettle ...

  7. winform频繁刷新导致界面闪烁解决方法

    转自龙心文 原文 winform频繁刷新导致界面闪烁解决方法 一.通过对窗体和控件使用双缓冲来减少图形闪烁(当绘制图片时出现闪烁时,使用双缓冲) 对于大多数应用程序,.NET Framework 提供 ...

  8. 一次性show 出所有配置

    cisco的全页打印显示配置信息的命令: #terminal length 0 #show run 华为和H3C的全页打印显示配置信息的命令: ]user-interface vty 0 4 ]scr ...

  9. ActionMQ5.8.0 JMS实例 手把手详细图解

    出自:http://blog.csdn.net/tongjie008/article/details/40687087 ActionMQ 是开源的JMS实现 1.下载ActiveMQ 去官方网站下载: ...

  10. Linux监控和安全运维 2.0 zabbix配置邮件告警

    1.发邮件启动postfix /etc/init.d/postfix start mail -s @qq.com < /etc/inittab mailq 查看发送结果 2.配置发邮件文件 mk ...