springboot javafx jdk11 打包成exe安装文件

介绍说明

环境说明

  • 使用jdk 11开发
  • 使用springboot 2.2.5.RELEASE
  • 使用javafx 11
  • 使用jfoenix美化javafx
  • 引入springboot-javafx-support结合springboot与javafx
  • idea 2020.1.1
  • 网上其他方案jdk过老或者不支持springboot与javafx结合

使用工具

  • maven: class -> jar,lib
  • launch4j: jar -> exe
  • inno setup: exe,lib -> 可安装exe

下载

  • launch4j:http://launch4j.sourceforge.net/
  • inno setup:可通过360软件管家安装
  • 设置Launch4j 系统环境变量 C:\Program Files (x86)\Launch4j

没有将jre环境填充到exe中,使用的系统已经安装java环境,读者可自行尝试。

使用
springboot-javafx-support

springboot-javafx-support结合后,需要一个静态入口类,启动springboot。

原因与 jdk的模块化和javafx脱离jdk有关。

ApplicationLauncher.class

/**
 * 启动入口
 *
 * @author liaozesong
 */
public class ApplicationLauncher {
    public static void main(String[] args) {
        TelesemeSpringApplication.run(args);
    }
}

TelesemeSpringApplication.class

/**
 * 加入springboot支持的fx
 *
 * @author liaozesong
 */
@SpringBootApplication
@ConfigurationPropertiesScan
@EnableConfigurationProperties
@EnableScheduling
@EnableTransactionManagement
@EnableCaching
public class TelesemeSpringApplication extends AbstractJavaFxApplicationSupport {
    public static void run(String[] args) {
        GtSplashScreen gtSplashScreen = new GtSplashScreen();
        launch(TelesemeSpringApplication.class, MainView.class, gtSplashScreen, args);
    }

    @Override
    public Collection<Image> loadDefaultIcons() {
        return Collections.singletonList(new Image(getClass().getResource("/img/icon.png").toExternalForm()));
    }
}
项目结构

在这里插入图片描述

maven

pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.guotie.idc.teleseme.ApplicationLauncher</mainClass>
                        </manifest>
                    </archive>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </configuration>
            </plugin>

            <!--拷贝依赖jar 到lib 目录-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--拷贝相关待使用文件到zip中-->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven-assembly-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>exe/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

assembly.xml

<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>${project.artifactId}</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>target</directory>
            <outputDirectory>${file.separator}</outputDirectory>
            <includes>
                <include>lib/**</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>

        <fileSet>
            <directory>exe</directory>
            <outputDirectory>${file.separator}</outputDirectory>
            <includes>
                <include>*</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>

        <fileSet>
            <directory>target</directory>
            <outputDirectory>${file.separator}</outputDirectory>
            <includes>
                <include>${project.artifactId}-*.jar</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
    </fileSets>
</assembly>

结果

点击idea中maven package生成以下结果

在这里插入图片描述

解压后为

在这里插入图片描述

launch4j

launch4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
    <dontWrapJar>false</dontWrapJar>
    <headerType>gui</headerType>
    <!--需修改-->
    <jar>C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\tools-input-dw-teleseme-1.0.0.jar</jar>
    <!--需修改-->
    <outfile>C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\tools-input-dw-teleseme-1.0.0.exe</outfile>
    <errTitle></errTitle>
    <cmdLine></cmdLine>
    <chdir>.</chdir>
    <priority>normal</priority>
    <downloadUrl>http://java.com/download</downloadUrl>
    <supportUrl></supportUrl>
    <stayAlive>false</stayAlive>
    <restartOnCrash>false</restartOnCrash>
    <manifest></manifest>
    <!--需修改-->
    <icon>C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\icon.ico</icon>
    <jre>
        <!--需修改-->
        <path>D:\soft\jdk-11</path>
        <bundledJre64Bit>false</bundledJre64Bit>
        <bundledJreAsFallback>false</bundledJreAsFallback>
        <minVersion></minVersion>
        <maxVersion></maxVersion>
        <jdkPreference>preferJre</jdkPreference>
        <runtimeBits>64/32</runtimeBits>
    </jre>
</launch4jConfig>

运行

cmd中输入 launch4jc.exe launch4j.xml生成 exe

在这里插入图片描述

inno setup

inno.iss 注意为gbk编码

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "xxxxx 入库工具"
#define MyAppVersion "1.0"
#define MyAppPublisher "xxx xxxx xxxx Co.,Ltd"
#define MyAppURL "http://www.xxxxxx.com/"
#define MyAppExeName "tools-input-dw-teleseme-1.0.0.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D3AE00CC-79E7-41B4-9903-294C312B57FD}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\guotie-tools-idc-teleseme
DisableDirPage=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=commandline
OutputDir=C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0
OutputBaseFilename=xxxxxx 入库工具
SetupIconFile=C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\icon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\tools-input-dw-teleseme-1.0.0.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Administrator\Desktop\tools-input-dw-teleseme-1.0.0\lib\*"; DestDir: "{app}\lib"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent


运行

双击inno.iss文件,打开inno setup软件

点击运行按钮,生成exe可安装文件。

在这里插入图片描述

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值