目标:可执行文件、配置文件、库、静态资源文件分开打包
优点:
1、方便修改配置
2、 方便前后端分离整合(前端工程直接拷贝到resources)
打包
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application*.yml</exclude>
<exclude>application*.properties</exclude>
<exclude>bootstrap*.yml</exclude>
<exclude>bootstrap*.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- 替换文件中maven properties相关的属性值 -->
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${profileActive}.yml</include>
<include>application.properties</include>
<include>application-${profileActive}.properties</include>
<include>bootstrap.yml</include>
<include>bootstrap-${profileActive}.yml</include>
</includes>
</resource>
<resource>
<directory>cmd</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/${project.artifactId}/</targetPath>
</resource>
<resource>
<directory>nsis</directory>
<filtering>false</filtering>
<targetPath>${project.build.directory}/${project.artifactId}/</targetPath>
</resource>
<resource>
<directory>cardLib</directory>
<filtering>false</filtering>
<targetPath>${project.build.directory}/${project.artifactId}/lib/cardLib</targetPath>
</resource>
<resource>
<directory>faceLib</directory>
<filtering>false</filtering>
<targetPath>${project.build.directory}/${project.artifactId}/lib/faceLib</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--拷贝第三方依赖文件到指定目录-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!--target/lib是依赖jar包的输出目录,根据自己喜好配置-->
<outputDirectory>${project.build.directory}/${project.artifactId}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="${project.build.directory}/${project.artifactId}/jre" overwrite="true" >
<fileset dir="C:\soft\Java\jdk8_64\jre" />
</copy>
<copy file="${project.build.directory}/${project.artifactId}.jar" tofile="${project.build.directory}/${project.artifactId}/bin/${project.artifactId}.jar"></copy>
<!-- <exec executable="C:\NSIS\Bin\makensis.exe">
<arg line="${project.build.directory}/${project.artifactId}/fids.nsi"></arg>
</exec>-->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
启动命令
echo off
set cwd=%~dp0
set path=%cwd%\jre\bin;%cwd%\faceLib;%path%
cd %cwd%
start %cwd%\jre\bin\javaw -Dfile.encoding=UTF-8 -classpath %cwd%lib\*;%cwd%jre\lib\*;%cwd%jre\lib\ext\*;%cwd%bin\* com.cares.witfids.WitFidsApplication
windows 将springboot 打包成exe安装包
使用NSIS工具
NSIS 打包脚本
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "yantai_fids"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "南京研发中心"
!define PRODUCT_WEB_SITE "http://www.cares.sh.cn"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\start.cmd"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "fids.ico"
!define MUI_UNICON "fids.ico"
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "license.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "FidsInstaller.exe"
InstallDir "$PROGRAMFILES\$PRODUCT_NAME"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File "fids.ico"
File "license.txt"
File "start.cmd"
File /r "jre"
File /r "lib"
File /r "bin"
CreateDirectory "$SMPROGRAMS\$PRODUCT_NAME"
CreateShortCut "$SMPROGRAMS\$PRODUCT_NAME\$PRODUCT_NAME.lnk" "$INSTDIR\start.cmd" "" "$INSTDIR\fids.ico"
CreateShortCut "$DESKTOP\$PRODUCT_NAME.lnk" "$INSTDIR\start.cmd" "" "$INSTDIR\fids.ico"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\$PRODUCT_NAME\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\$PRODUCT_NAME\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\start.cmd"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\fids.ico"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ytFidsClient" "$INSTDIR\start.cmd"
SectionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Delete "$SMPROGRAMS\$PRODUCT_NAME\Uninstall.lnk"
Delete "$SMPROGRAMS\$PRODUCT_NAME\Website.lnk"
Delete "$DESKTOP\$PRODUCT_NAME.lnk"
Delete "$SMPROGRAMS\$PRODUCT_NAME\$PRODUCT_NAME.lnk"
RMDir "$SMPROGRAMS\$PRODUCT_NAME"
RMDir /r /REBOOTOK $INSTDIR
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ytFidsClient"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
linux 将springboot 打包成rpm 安装包
待续。。。
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!