web項目打包成exe在windows下一鍵安裝 jdk+Tomcat+mysql

來源:互聯網
上載者:User

標籤:specific   unless   ppi   cond   over   tar   註冊   needed   publish   

      最近因為公司銷售人員不懂軟體,所以每次部署項目都需要技術人員到客戶現場進行部署,很不方便。所以公司就讓把我們的項目做成傻瓜式安裝,這樣就可以讓銷售人員去安裝,也給技術省了很多事。我在網上找了很多教程但是有些地方還是不全,而且每個人寫的也都不一樣,所以在製作過程中遇到很多問題,經過幾天研究終於實現了,現在就把我整理、研究的寫下來,希望可以幫到更多人。

一:打包工具

在網上下載一個 Inno steup的製作exe檔案工具

下面是我整理好的compile.iss檔案(以下這個可以直接複製過去把要改的東西改掉就可以直接用了):

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

#define MyAppName "xxxx管理系統"        <------軟體的名稱
#define MyAppVersion "V1.0"           <-------軟體的版本
#define MyAppPublisher "xxxxxx資訊科技有限公司"    <------公司名稱
#define MyAppURL "http://www.xxxx.com/"          <------公司網址

[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={{DCCFE898-2E2D-4C7B-9A45-C81B3A50F80C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=D:\soft         <------預設安裝的路徑
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
SetupIconFile=C:\Users\g5000\Desktop\soft\logo.ico   <------安裝表徵圖的路徑
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin


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

[Files]         <------需要打包成exe檔案的jdk+Tomcat+mysql檔案的路徑
Source: "C:\Users\g5000\Desktop\soft\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don‘t use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\xxxxxx理系統"; Filename: http://localhost:9080     <------ tomcat訪問的連接埠,這裡改成9080是為了避免衝突

[Run]     <------ 一鍵安裝後要運行一下三個bat檔案,Flags: runhidden; 表示運行是隱藏的
Filename: "{app}\tomcat6\Set_Env.bat"; Flags: runhidden;   
Filename: "{app}\tomcat6\bin\啟動服務.bat"; Flags: runhidden;
Filename: "{app}\MySQL\bin\啟動服務.bat"; Flags: runhidden;

 

 

二:jdk+Tomcat+mysql具體的修改和整理

1:三個檔案目錄:

 

 mysql:

tomcat6:

jdk(jdk放在tomcat的bin目錄下):

2:需要修改或建立的檔案

mysql的my.ini檔案:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

character_set_server=utf8


# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
port = 3307
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]
port=3307
default-character-set=utf8
[mysql]
default-character-set=utf8

啟動服務.bat檔案:

cd /d %~dp0
"%cd%\mysqld.exe" -install HQmysql
net start HQmysql
"%cd%\mysqladmin" -u root password root

 

tomcat6的Set_Env.bat檔案(jdk,配置環境變數並寫到註冊表裡去):

 

@echo off
echo
cd ..
echo  "%~dp0"
echo "%cd%"
set jdkpath=%cd%\tomcat6\bin\Java\jdk1.6.0_45
echo %jdkpath%
setx JAVA_HOME  "%jdkpath%"  -m
setx CLASSPATH  ".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar" -m
echo %Path%
echo %Path%|find /i "%java_home%" && set IsNull=true || set IsNull=false
echo %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" /f
setx Path "%%JAVA_HOME%%\bin;%Path%"
)
exit

 

tomcat啟動服務.bat檔案:

echo
call "%~dp0%service.bat" install tomcat6
echo
sc config tomcat6 start= auto
sc start tomcat6
rem 下面兩句是設定到服務裡自動啟動的
wmic service where name="tomcat6" changestartmode "automatic"
wmic service where name="tomcat6" startservice
exit

 

下面重點說下tomcat的service.bat檔案,因為這個檔案要配置tomcat6w.exe檔案的java裡的jvm

,如果不配置好服務裡的tomcat是無法啟動的,啟動就會報。而且tomcat6w.exe也打不開,會出現這個錯誤。所以service.bat檔案很重要,下面給出我修改的service.bat,可以把這個複製下去後用beyond compare這個工具和原來tomcat裡的service.bat檔案比較下就可以清楚的看到我修改的東西。如果想弄清楚service.bat檔案裡語句的走向流程的話可以在開始的時候把@echo off改成@echo on然後在結尾的地方加暫停(pause),然後儲存下,雙擊運行,就會彈出

然後把這裡面的語句和service.bat裡的語句進行對比就會明白service裡語句是怎麼啟動並執行,以及它的作用。

 

service.bat配置如下:

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem NT Service Install/Uninstall script
rem
rem Options
rem install                Install the service using Tomcat6 as service name.
rem                        Service is installed using default settings.
rem remove                 Remove the service from the System.
rem
rem name        (optional) If the second argument is present it is considered
rem                        to be new service name
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
rem if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%cd%"
if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHome
rem CD to the upper dir
cd ..
set "CATALINA_HOME=%cd%"  
:gotHome
if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHome
echo The tomcat6.exe was not found...
echo The CATALINA_HOME environment variable is not defined correctly.
echo This environment variable is needed to run this program
goto end
:okHome
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo Service will try to guess them from the registry.
goto okJavaHome
:gotJreHome
if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
goto okJavaHome
:gotJdkHome
set "JRE_HOME=%JAVA_HOME%\jre"
if not exist "%JAVA_HOME%\jre\bin\java.exe" goto okJavaHome
if not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
if not "%JRE_HOME%" == "" goto okJavaHome
set "JRE_HOME=%JAVA_HOME%\jre"
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
echo NB: JAVA_HOME should point to a JDK not a JRE
goto end
:okJavaHome
if not "%CATALINA_BASE%" == "" goto gotBase
set "CATALINA_BASE=%CATALINA_HOME%"
:gotBase
 
set "EXECUTABLE=%CATALINA_HOME%\bin\tomcat6.exe"

rem Set default Service name
set SERVICE_NAME=Tomcat6
set DISPLAYNAME=HQTomcat6
if "x%1x" == "xx" goto doInstall
set SERVICE_CMD=%1
shift
if "x%1x" == "xx" goto checkServiceCmd
set SERVICE_NAME=%1
set DISPLAYNAME=HQTomcat6 %1
shift
if "x%1x" == "xx" goto checkServiceCmd
echo Unknown parameter "%1"
goto displayUsage
:checkServiceCmd
if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == uninstall goto doRemove
echo Unknown parameter "%SERVICE_CMD%"
:displayUsage
echo.
echo Usage: service.bat install/remove [service_name]
goto end

:doRemove
rem Remove the service
echo Removing the service ‘%SERVICE_NAME%‘ ...
echo Using CATALINA_BASE:    "%CATALINA_BASE%"

"%EXECUTABLE%" //DS//%SERVICE_NAME% ^
    --LogPath "%CATALINA_BASE%\logs"
if not errorlevel 1 goto removed
echo Failed removing ‘%SERVICE_NAME%‘ service
goto end
:removed
echo The service ‘%SERVICE_NAME%‘ has been removed
goto end

:doInstall
set "JRE_HOME=%JAVA_HOME%\jre"
rem Install the service
echo Installing the service ‘%SERVICE_NAME%‘ ...
echo Using CATALINA_HOME:    "%CATALINA_HOME%"
echo Using CATALINA_BASE:    "%CATALINA_BASE%"
echo Using JAVA_HOME:        "%JAVA_HOME%"
echo Using JRE_HOME:         "%JRE_HOME%"

rem Try to use the server jvm
rem set "JVM=%JRE_HOME%\bin\server\jvm.dll"
rem if exist "%JVM%" goto foundJvm
rem Try to use the client jvm

set "JVM=%JRE_HOME%\bin\client\jvm.dll"
if exist "%JVM%" goto foundJvm
echo Warning: Neither ‘server‘ nor ‘client‘ jvm.dll was found at JRE_HOME.
set JVM="%JAVA_HOME%\jre\bin\client\jvm.dll"
:foundJvm
echo Using JVM:              "%JVM%"

set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar"
if not "%CATALINA_HOME%" == "%CATALINA_BASE%" set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"

"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
    --Description "Apache Tomcat 6.0.45 Server - http://tomcat.apache.org/" ^
    --DisplayName "%DISPLAYNAME%" ^
    --Install "%EXECUTABLE%" ^
    --LogPath "%CATALINA_BASE%\logs" ^
    --StdOutput auto ^
    --StdError auto ^
    --Classpath "%CLASSPATH%" ^
    --Jvm "%CATALINA_HOME%\bin\Java\jdk1.6.0_45\jre\bin\client\jvm.dll" ^
    --StartMode jvm ^
    --StopMode jvm ^
    --StartPath "%CATALINA_HOME%" ^
    --StopPath "%CATALINA_HOME%" ^
    --StartClass org.apache.catalina.startup.Bootstrap ^
    --StopClass org.apache.catalina.startup.Bootstrap ^
    --StartParams start ^
    --StopParams stop ^
    --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" ^
    --JvmMs 128 ^
    --JvmMx 256
if not errorlevel 1 goto installed
echo Failed installing ‘%SERVICE_NAME%‘ service
goto end
:installed
echo The service ‘%SERVICE_NAME%‘ has been installed.

:end
cd "%CURRENT_DIR%"

主要的東西都在這裡,然後還有tomcat連接埠的配置我在這裡就不說了。參考部落格:

http://blog.csdn.net/liuhaomatou/article/details/52576162

 

 

 

web項目打包成exe在windows下一鍵安裝 jdk+Tomcat+mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.