背景,最近公司要做java的本地化服务,需要在用户的终端部署安装java的服务,目前设计的进行http服务,从而提高云服务的容错性、性能,顺便进行有其他window的模块的连接。
因为不是所有的本地业务模块都会打入本地服务,根据不同的需求,选择不同的模块打包。
1 model多model打包
使用多profile实现选择模块的打包。
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency> 模块
<groupId>com.aa</groupId>
<artifactId>xx</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>模块
<groupId>com.xx</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>模块
<groupId>com.xx</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>rentai</id>
<dependencies>
<dependency>
<groupId>com.aa</groupId>
<artifactId>xx</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.aa</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
在ide中选择使用的想要依赖运行的profile:
在打包的时候选择选择profile,则打包出来的jar,因为是spring boot的模块,在生成的jar中,是所有的依赖包在jar中的。
2 launch4j打exe执行包
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>pos-offline</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>console</headerType>
**<jar>${project.build.directory}/${artifactId}-${version}.jar</jar>** 选择要打包的jar,
<outfile>${project.build.directory}/xxx-boot.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
**<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>** 如果是spring boot的支撑框架,这个mainclass是固定的。
<preCp>anything</preCp>
</classPath>
<!--<icon>src/resources/0.ico</icon>-->
<jre>
<jdkPreference>jdkOnly</jdkPreference>
<path>./jre</path>
<minVersion>1.7.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>2019 pos-boot.com</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<!--<companyName>hasCode.com</companyName>-->
<internalName>xxx-client</internalName>
<originalFilename>pos-client.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
3 inno setup打安装包
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "xxx-client"
#define MyAppVersion "1.0"
#define MyAppPublisher "xxxxxx"
#define MyAppExeName "xxx-client.exe"
#define MyAppExeBatName "start.vbs"
[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={{2AAF05F0-A7E5-4493-AA77-D38D8B9BC5C7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
OutputBaseFilename=xxx_client_setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
;Name: "startupicon"; Description: "开机启动"; GroupDescription: "{cm:AdditionalIcons}";
[Files]
;Source: "..\target\xxx-0.0.1-SNAPSHOT.jar"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\target\xxx-boot.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\main\resources\application-prod.properties"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\run\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
; note : db文件的处理
[Icons]
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
;Name: "{userstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeBatName}"; Tasks: desktopicon
[Registry]
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "testrun"; ValueData: "{app}\{#MyAppExeBatName}"
;注册表
[Run]
Filename: "{app}\{#MyAppExeBatName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppExeBatName,'&','&&')}}"; Flags:shellexec nowait postinstall skipifsilent
;开机启动
[code]
//删除所有配置文件以达到干净卸载的目的
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
if MsgBox('您是否要删除用户配置信息?', mbConfirmation, MB_YESNO) = IDYES then
//删除 {app} 文件夹及其中所有文件
DelTree('{app}', True, True, True);
end;
在iss文件的统计目录中,则有一个文件夹,有一个安装程序,则完成