BAT batch completes installation of JDK Tomcat

Source: Internet
Author: User

After completing a Web application project, the leader asks for a configuration batch file that automates the installation of the JDK, the installation of Tomcat, the deployment of the Web application, the registration of environment variables, the installation and automatic start of the Tomcat service

After referencing a lot of similar batch code on the Web, the following batch processing is integrated

The scenario is to install the JDK first, then copy the deployed Web app together with the extracted Tomcat folder (not the installation version, which is simpler) to the destination directory, then write the environment variables and then register the service.

First file Setup-1.bat

@echo off%1Mshta Vbscript:createobject ("shell.application"). ShellExecute ("Cmd.exe","/ C%~s0::","","runas",1) (Window.close) &&ExitSetMyjdkpath=c:\java\1.8. 0_60SetMyjrepath=c:\java\1.8. 0_60\jreSetmytomcatpath=c:\apache-tomcat-8.0. -Echo**********************************************Echo.echo to install Jdkecho.echo install please press any key to exit the window directly Echo.echo**********************************************Pauseecho.echo Installing the JDK, please do not perform other operations Echo.echo Please wait a moment, this time takes about two or three minutes Echo.start/wait jdk-8u60-windows-x64.exe/qn installdir=c:\java\1.8. 0_60echo JDK Installation complete echo**********************************************Echo.echo will install the Tomcat software Echo.echo install Press any key to exit the direct close window Echo.echo**********************************************Pauseecho.echo Installing Tomcat Please do not perform other operations Echo.echo Please wait a moment, this time takes about five or six minutes echo.xcopy/e/i apache-tomcat-8.0. -c:\apache-tomcat-8.0. ->Nulecho Tomcat installation complete echo**********************************************Echo.echo To install the configuration environment variable Echo.echo continue press any key to exit the direct close window Echo.echo**********************************************Pausesetx jre_home%myjrepath%>Nulsetx Java_home%myjdkpath%>nulsetx CLASSPATH.;%myjdkpath%\lib\tools.jar;%myjdkpath%\lib\dt.jar;%myjdkpath%\jre\lib\rt.jar>Nulsetx PATH%myjdkpath%\bin>Nulsetx catalina_home"%mytomcatpath%">NULECHO environment variable is configured successfully. Please run Setup manually after echo exits-2. bat, press any key to exit pause

A second file Setup-2.bat

Echo.echo            set up and start the Tomcat       service Echo.echo************** pausecall C:\apache-tomcat-8.0. \bin\service.bat install>NULSC config Tomcat8 start= auto>nulnet start Tomcat8 Echo Deployment has completed successfully, press any key to exit pause

Here's a question of why you need to run the two files manually instead of a bat.

The answer is that bat finishes writing environment variables and restarts to take effect! BAT will not take effect until it finishes writing environment variables! BAT will not take effect until it finishes writing environment variables! (important thing to say three times)

The second file installs the Tomcat service when the environment variable is required, which is always reported in a file when the environment variable catalina_home error, but I use the command line to install the service alone can be installed successfully, that is, the display environment variables are not wrong! Toss for a long time, then suddenly thought of this possibility.  (Too much food, please laugh at me) The result was a test. I also wanted to write the third bat to invoke the two bat, but this is still an old problem, it seems that even if the third bat calls the two bat, they are in a thread.

So at present, the method of manually running these two files separately is used. If there is an improvement plan, then add it.

BAT batch completes installation of JDK Tomcat

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.