Tomcat 通过java程序启动和停止,以及解决The CATALINA_HOME environment variable is not defined correctlyThis environ
2017-09-30 23:01
671 查看
package com.example.springboot.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;/*** @Author: HONGLINCHEN* @Description:程序启动tomact和关闭* @Email: xychenhonglin@163.com* @Date: 2017-9-30 23:00*/public class StartTomcat {public void close() throws IOException{Process process = Runtime.getRuntime().exec("cmd /c E:\\apache-tomcat-7.0.79\\bin\\shutdown.bat"); // 调用外部程序final InputStream in = process.getInputStream();BufferedReader br=new BufferedReader(new InputStreamReader(in));StringBuilder buf = new StringBuilder();String line = null;while((line = br.readLine()) != null)buf.append(line);System.out.println("输出结果为:" + buf);}public void start() throws IOException{Process process = Runtime.getRuntime().exec("cmd /c E:\\apache-tomcat-7.0.79\\bin\\startup.bat"); // 调用外部程序final InputStream in = process.getInputStream();BufferedReader br=new BufferedReader(new InputStreamReader(in));StringBuilder buf = new StringBuilder();String line = null;while((line = br.readLine()) != null)buf.append(line);System.out.println("输出结果为:" + buf);}
public static void main(String[] args) throws Exception{// TODO Auto-generated method stubStartTomcat con=new StartTomcat();con.start();//con.close();}}cmd /c 可以不要如果启动不成功,控制台打印下面的提示,The CATALINA_HOME environment variable is not defined correctlyThis environment variable is needed to run this program第一请检查tomcat环境变量的配置第二打开tomcat bin目录下,找到startup.bat用motepad++编辑找到set "CURRENT_DIR=%cd%"这段 改成set "CURRENT_DIR=E:\apache-tomcat-7.0.79"注意 只有一对双引号 %%去掉同理如果运行shutdown.bat也提示上面的错,那么shutdown.bat文件中set "CURRENT_DIR=%cd%"这段 也要改成set "CURRENT_DIR=E:\apache-tomcat-7.0.79"
相关文章推荐
- 在idea启动tomcat出现The JAVA_HOME environment variable is not defined correctly的解决
- 双击startup.bat,启动不了tomcat,JAVA_HOME environment variable is not defined correctly
- 解决Intellij Idea里tomcat启动报The JRE_HOME environment variable is not defined correctly的错误
- 双击startup.bat,启动不了tomcat,JAVA_HOME environment variable is not defined correctly
- tomcat启动一闪而过解决办法报错The CATALINA_HOME environment variable is not defined correctly
- idea创建web项目时启动tomcat出现The JAVA_HOME environment variable is not defined correctly
- 2个问题,解决tomcat启动一闪而过和运行tomcat/bin目录下的startup.bat时报错(the CATALINA_HOME environment variable is not defined correctly)
- windows tomcat 启动报错TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly
- tomcat配置环境变量后在cmd中输入startup出现the JRE_HOME environment variable is not defined correctly This environ
- Tomcat启动报错,The CATALINA_HOME environment variable is not defined correctly
- Tomcat之the jre_home environment variable is not defined correctly this environment variable is need
- 关于Tomcat,startup JAVA_HOME or JRE_HOME environment variable is not defined correctly解决方案
- (转)TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly(2013-03-29 13:04:14)
- 解决Linux下启动Tomcat遇到Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly
- 解决Linux下启动Tomcat遇到Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- 运行Tomcat出现the JRE_HOME environment variable is not defined correctly 的解决办法
- TOMCAT启动时报错:the CATALINA_HOME environment variable is not defined correctly
- tomcat配置环境变量后在cmd中输入startup出现the JRE_HOME environment variable is not defined correctly This environ
- 启动Tomcat错误:he JRE_HOME environment variable is not defined correctly