Windows one-click Deployment Java Project

Source: Internet
Author: User
Tags influxdb

Windows one-click Deployment Java Project

Because of the company's needs, to do a one-click deployment in the Windows environment to start the Java project, but also to support the dynamic modification of the configuration file from the installation interface IP address. Install and configure the Jdk,tomcat,mysql,influxdb,nginx to the system just as you would install the software, and initialize the data. It took me a week to record my pit log.

Preparatory work

AX, choosing a good tool can do more with less.
A), Inno Setup, a free installer for Windows programs, which allows you to package the required file compression into an EXE installer and unzip it into another environment like a setup program. Official address
ii), virtual machine, two role: the first can avoid playing bad own computer, the second can ensure that each test installation of the environment is a clean system, reduce some unnecessary trouble.
(iii), JDK1.8,MYSQL5.7,TOMCAT8,NGINX,INFLUXDB, etc., this is a file resource that needs to be compressed.
Four), Windows Server R2, you deserve to have, with 2008 install MySQL will be very bad.

Inno Setup Foundation uses

Inno Setup has almost the same template, and if you need a custom interface, you can add code to it in [code]. For example, I need to add a custom interface with an input box during installation, replace the input value with the specified content in the configuration file, and create a shortcut key on the desktop after the installation is successful.
for the Bat scripting language is very weak I say there are two difficulties, but according to gourd painting can still be done.
a), Inno setup functions, in the [code] block, you can customize a lot of features to achieve custom development, you can refer to the online documentation
II), you need to configure the JDK environment variables with the bat script, install the deployment tomcat, install and deploy MySQL.

#define MYAPPNAME "Custom program name" #define MYAPPVERSION "V1.0" #define Myapppublisher "custom program publisher" #define Myappurl "http://www.xxxx.com/"; Basic configuration [Setup]; Note:the value of AppId uniquely identifies this application.; The same AppId value in installers for other applications. (to generate a new GUID, click Tools | Generate GUID inside the IDE.); Individually identifiable, can be automatically generated by the Innosetup-qsp-5.6.1.exe tool appid={{0167d65d-549a-4ba3-b88a-4814ec5a1d35}appname={#MyAppName} appversion={#MyAppVersion}apppublisher={#MyAppPublisher}apppublisherurl={#MyAppURL}appsupporturl={#MyAppURL} appupdatesurl={#MyAppURL}; Default installation path Defaultdirname=c:\program files\itdragondefaultgroupname={#MyAppName}; Software name Outputbasefilename=itdragon; Software icon Setupiconfile=c:\users\long\desktop\ok\itdragon\itdragon.ico; Compression mode Compression=lzma; Yes to make the file smaller solidcompression=yes; Must have administrator privileges to install privilegesrequired=admin; Install password; Password=itdragon; Turn on encryption, you may also need a DLL file; Encryption=yes; Language configuration [languages]name: "中文版"; Messagesfile: "Compiler:default.ISL "; installation file [files]; The source file path of the installation deployment: "c:\users\long\desktop\itdragon\*"; DestDir: "{app}"; Flags:ignoreversion Recursesubdirs Createallsubdirs; Note:don ' t use "flags:ignoreversion" on any shared system files; Shortcut key [Icons]name: "{group}\{cm:uninstallprogram,{#MyAppName}}"; Filename: "{uninstallexe}" Name: "{commondesktop}\ Express http Address"; Filename:http://localhostname: "{commondesktop}\mysql data initialization script"; Filename: "{app}\mysql\init-data.bat" Name: "{commondesktop}\ installation Notice"; Filename: "{app}\ installation notes. doc"; Execute script after successful installation [Run] Filename: "{app}\tomcat\init-jdk.bat"; Filename: "{app}\tomcat\bin\init-tomcat.bat"; Filename: "{app}\mysql\bin\init-mysql.bat";; Enter the IP address when installing, and dynamically change localhost to the input value [code]varmypage:twizardpage;//custom window ed1:tedit;//custom Input box lbl1:tnewstatictext;// Custom title//Initialize boot window procedure initializewizard (); Beginmypage:=createcustompage (wpwelcome, ' Configure Service IP address ', enter the correct IP address, Have ensured the normal use of the service '); LBL1: = Tnewstatictext.create (MyPage); Lbl1.left: = ScaleX (5); Lbl1.top: = ScaleY (5); Lbl1.width: = ScaleX (250); Lbl1.height: = ScaLeY (50); Lbl1.caption: = ' IP address input box header '; Lbl1.parent: = Mypage.surface;ed1:=tedit.create (MyPage); ed1. Width:=scalex (410); ed1. Top: = ScaleY (+); ed1. Text: = ' 127.0.0.1 '; ed1.    Parent:=mypage.surface;end;procedure curstepchanged (curstep:tsetupstep); var filename:string;    svarray:tarrayofstring; Nlines,i:integer;begin//Copy file after execution if curstep = Sspostinstall THEN begin fileName: = Expandconstant (' {App}\nginx\html\ma  In.bundle.js ');  Loadstringsfromfile (FileName, Svarray);//Read file Nlines: = Getarraylength (Svarray); For I: = 0 to NLines-1 do if (0 < Pos (' localhost ', svarray[i]) then//find target Stringchange (svarray[i], ' localhost ' , ed1.    Text);  Savestringstoutf8file (FileName, Svarray, false); End;end;

Attention:
A), if you don't need a custom function, the [code] block can be erased
Second), click on Inno Setup on the Compile button to start compiling, the compilation will be successful in an output folder generated EXE file, the output directory is generally the same level as the ISS file.

Configuring the JDK environment variables

In doing this demand, read a few articles, found that they all put the JDK in the Tomcat directory, the first time to do is also foolishly placed in the Tomcat directory, in fact, not necessary. And the current mainstream Springboot project is embedded Tomcat. Create a new bat script to run the Java program java -jar xxx.jar after the installation succeeds in generating a shortcut key on the desktop, allowing the user to double-click the Start service. If you have a reasonable method, you can tell me!!!
Init-jdk.bat, content source network, requires a directory-level relationship when modifying:

@echo off echocd ..echo  "%~dp0"echo "%cd%"set jdkpath=%cd%\tomcat\bin\java\jdkecho %jdkpath%setx JAVA_HOME  "%jdkpath%"  -msetx CLASSPATH  ".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar" -mecho %Path%echo %Path%|find /i "%java_home%" && set IsNull=true || set IsNull=falseecho %IsNull%if not %IsNull%==true (reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_SZ /d "%Path%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin" /fsetx Path "%%JAVA_HOME%%\bin;%Path%")exit
Tomcat Installation Deployment

Need to put the Init-tomcat.bat file in the Tomcat/bin directory, there is a blog said to modify the Service.bat file, I do not modify still can start normally. When you look at other people's blogs, you can try to jump through the areas you don't understand. I just silly down a tomcat6, compare the difference between the two ...

echo -------tomcat begin--------call "%~dp0%service.bat" install tomcat8echo -------tomcat install end------------------sc config tomcat8 start= autonet start tomcat8exit
MySQL Installation deployment

MySQL installation needs to note two points: first set the database initial password, the second set the database encoding format,
A), the initialization of the database do not generate a password, convenient late modification, commandmysqld.exe --initialize-insecure --user=mysql --console
Second), the database encoding format to unify for UTF8, many online methods are in the My.ini file configuration encoding format, can MySQL5.7 without the file, do not create one. MySQL5.6 If you manually create a My.ini file, you may have a problem starting the service.
Init-mysql.bat, content source network, slightly modified.

cd /d %~dp0 cd ..set inipath=%cd%\my.inicd bin"%cd%\mysqld.exe" -install mysql --defaults-file="%inipath%""%cd%\mysqld.exe" --initialize-insecure --user=mysql --consolenet start mysqlsc config mysql start=auto net stop mysqlnet start mysqlecho 安装完毕 "%cd%\mysqladmin.exe" -u root password rootecho 修改密码完毕 cd .. "%cd%\bin\mysql.exe" -uroot -proot < "%cd%\sqlfile\initMysql.sql" echo 数据库初始化完成 pause;

Initmysql.sql

create database IF NOT EXISTS itdragon_data character set utf8;set global character_set_database=utf8;set global character_set_server=utf8;
Encounter the Pit

With the Inno Setup tool, one-click deployment of the Configuration Web project becomes simple, just to compress the deployed resources into an EXE file, and then click on the exe file to perform the auto-run BAT file initialization configuration after the successful installation. But I still spend a lot of time. There are several reasons:
One), the environment that started installation is Windows Server 2008, and the installation of MySQL5.7 failed because the advanced read-write locks provided by MySQL5.7 are not supported. Later replaced by the MySQL5.6 installation succeeded
II), MySQL5.6 start service failed 1067, there are many solutions on the Internet, not a success. Helpless changed Windows Server R2, the result was a success.
Third), the Inno Setup function is not familiar with, the resource file is too large, each compilation debugging to wait half an hour.

The article ends here, influxdb and Nginx are simpler, the same logic. I hope you will use your time in the right place. If you feel good you can order a "recommendation"

Reference article:
52576162

72462688

Windows one-click Deployment Java Project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.