Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn on and off tomcat server by Java

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how Java turns on and off the tomcat server. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

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"; / / launch the tomcat command / / string command = "e:\\ apache-tomcat-7.0.76\\ bin\\ tomcat7w.exe" / / start the tomcat command, windows version only, no pop-up box string command = "e:\\ apache-tomcat-7.0.76\\ bin\\ shutdown.bat"; / / close the tomcat command calltomcat calltomcat = new calltomcat (); try {calltomcat.callcommand (command);} catch (ioexception e) {system.out.println ("error executing command:" + e.getmessage ()) }} / * execute the command * * @ throws ioexception * / private void callcommand (string command) throws ioexception {runtime runtime = runtime.getruntime (); / / return the runtime object related to the current java application / / instruct the java virtual machine to create a child process to execute the specified executable and return the process object instance process process = runtime.exec (command) corresponding to the child process; runtime.gc () / / run garbage collector string line = null; string content = ""; bufferedreader br = new bufferedreader (new inputstreamreader (process.getinputstream (); while ((line = br.readline ())! = null) {content + = line + "\ r\ n";} system.out.println (content);}}

3. Effect preview

3.1 execute the open command

3.2 execute the close command

4. Common mistakes

It may occur after the code is executed:

The catalina_home environment variable is not defined correctly

This environment variable is needed to run this program

At this point, you need to set the environment variable:

After I set it up, I still report an error, but log off the computer and run it again.

5. Description

If you execute startup.bat, a pop-up box will appear automatically, but if you execute tomcat7w.exe (depending on the tomcat version), no pop-up box will appear. -- only the windows version, other versions do not have .exe files.

These are all the contents of the article "how to turn Java on and off tomcat Server". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report