In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Project structure
2.CallTomcat.java
package com.calltomcat.test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CallTomcat { public static void main (String[] args) { //String command = "E:\\apache-tomcat-7.0.76\\bin\\startup.bat";//Start tomcat command//String command = "E:\\apache-tomcat-7.0.76\bin\\tomcat7w.exe";/Start Tomcat command, windows version only, no pop-up box String command = "E:\\apache-tomcat-7.0.76\bin\\shutdown.bat";//Close tomcat command CallTomcat = new CallTomcat(); try { callTomcat.callCommand(command);} catch (IOException e) { System.out.println("Error executing command: " + e.getMessage()); } } /** * Execute command * * @throws IOException */ private void callCommand (String command) throws IOException { Runtime runtime = Runtime.getRuntime();//Returns the runtime object associated with the current Java application//instructs the Java virtual machine to create a child process to execute the specified executable program and returns the Process object instance corresponding to the child process Process = runtime.exec(command); runtime.gc();//run garbage collector String line = null; String content = ""; Buffered Reader br = new Buffered Reader (new InputStreamReader(process.getInputStream())); while((line = br.readLine()) != null) { content += line + "\r\n"; } System.out.println(content); }}
3. effect preview
3.1 Execute open command
3.2 Execute shutdown command
4. common mistakes
Executing the code may result in:
The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
You need to set environment variables:
I set up after the operation is still error, but the computer will log off to run again.
5. description
A pop-up box appears automatically if you execute startup.bat, but not if you execute tomcat7w.exe(which varies depending on the tomcat version). -- Windows version only, other versions do not have.exe files.
summary
The above is the Java open/close tomcat server method introduced by Xiaobian to you, I hope to help you, if you have any questions, please give me a message, Xiaobian will reply to you in time. Thank you very much for your support!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.