Java 如何使用CMD启动停止tomcat服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4499117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to start stop tomcat server using CMD?
提问by
I set the path for the tomcat and set all variables like
我设置了 tomcat 的路径并设置了所有变量,例如
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_22
CATALINA_HOME=G:\springwork\server\apache-tomcat-6.0.29
CLASSPATH=G:\springwork\server\apache-tomcat-6.0.29\lib\servlet-api.jar;G:\springwork\server\apache-tomcat-6.0.29\lib\jsp-api.jar;.;
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_22
CATALINA_HOME=G:\springwork\server\apache-tomcat-6.0.29
CLASSPATH=G:\springwork\server\apache-tomcat-6.0.29\lib\servlet-api.jar;G:\springwork\server\apache-tomcat-6.0.29\lib\jsp-api.jar;.;
When I go to bin folder and double click on startup.bat then my tomcat starts and when I double click on shutdown.bat tomcat stops.
当我转到 bin 文件夹并双击 startup.bat 时,我的 tomcat 启动,当我双击 shutdown.bat 时,tomcat 停止。
But I want using CMD start and stop the tomcat.
And in any folder I write command startup.bat
the server will start and when I write shutdown.bat
the server will stop.
但我想使用 CMD 启动和停止 tomcat。在我写命令startup.bat
的任何文件夹中,服务器将启动,当我写时shutdown.bat
服务器将停止。
采纳答案by Arun P Johny
Add %CATALINA_HOME%/bin
to path system variable.
添加%CATALINA_HOME%/bin
到路径系统变量。
Go to Environment Variables
screen under System Variables
there will be a Path
variable edit the variable and add ;%CATALINA_HOME%\bin
to the variable then click OK
to save the changes. Close all opened command prompts then open a new command prompt and try to use the command startup.bat
.
转到Environment Variables
屏幕下方System Variables
将有一个Path
变量编辑变量并添加;%CATALINA_HOME%\bin
到变量中,然后单击OK
以保存更改。关闭所有打开的命令提示符,然后打开一个新的命令提示符并尝试使用该命令startup.bat
。
回答by Ugrasen Banchhor
You can use the following command c:\path of you tomcat directory\bin>catalina run
可以使用如下命令 c:\path of you tomcat directory\bin>catalina run
回答by Carson Balzrette
This is what I used to start and stop tomcat 7.0.29, using ant 1.8.2. Works fine for me, but leaves the control in the started server window. I have not tried it yet, but I think if I change the "/K" in the startup sequence to "/C", it may not even do that.
这是我用来启动和停止tomcat 7.0.29的,使用ant 1.8.2。对我来说很好用,但将控件留在启动的服务器窗口中。我还没有尝试过,但我认为如果我将启动顺序中的“/K”更改为“/C”,它甚至可能不会这样做。
<target name="tomcat-stop">
<exec dir="${appserver.home}/bin" executable="cmd">
<arg line="/C start cmd.exe /C shutdown.bat"/>
</exec>
</target>
<target name="tomcat-start" depends="tomcat-stop" >
<exec dir="${appserver.home}/bin" executable="cmd">
<arg line="/K start cmd.exe /C startup.bat"/>
</exec>
</target>
回答by Ameer Chand
you can use this trick to run tomcat using cmd and directly by tomcat bin folder.
您可以使用此技巧使用 cmd 并直接通过 tomcat bin 文件夹运行 tomcat。
1. set the path of jdk.
1.设置jdk的路径。
2.
2.
To set path. go to Desktop and right click on computer icon. Click the Properties
要设置路径。转到桌面并右键单击计算机图标。单击属性
go to Advance System Settings.
转到高级系统设置。
then Click Advance to Environment variables.
然后单击前进到环境变量。
Click new and set path AS,
点击新建并设置路径AS,
in the column Variable name=JAVA_HOME
在列变量名=JAVA_HOME
Variable Value=C:\Program Files\Java\jdk1.6.0_19
变量值=C:\Program Files\Java\jdk1.6.0_19
Click ok ok.
单击确定确定。
now path is stetted.
现在路径已经确定。
3.
3.
Go to tomcat folder where you installed the tomcat. go to bin folder. there are two window batch files.
转到安装 tomcat 的 tomcat 文件夹。转到 bin 文件夹。有两个窗口批处理文件。
1.Startup
1.启动
2.Shutdown.
2.关机。
By using cmd if you installed the tomcate in D Drive
如果您在D 盘安装了 tomcate,则使用 cmd
type on cmd screen
在 cmd 屏幕上输入
D:
Cd tomcat\binthen type Startup.
乙:
cd tomcat\bin然后键入启动。
4. By clicking them you can start and stop the tomcat.
4. 通过单击它们,您可以启动和停止 tomcat。
5.
5.
Final step.
最后一步。
if you start and want to check it.
如果您开始并想检查它。
open a Browser in URL bar type.
在 URL 栏类型中打开浏览器。
**HTTP://localhost:8080/**
回答by Shashank G
Change directory to tomcat/bin directory in cmd prompt
在 cmd 提示符下将目录更改为 tomcat/bin 目录
cd C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin
cd C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin
Run the below command to start:
运行以下命令启动:
On Linux: >startup.sh
在 Linux 上:>startup.sh
On Windows: >startup.bat
在 Windows 上:>startup.bat
Run these commands to stop
运行这些命令停止
On Linux: shutdown.sh
在 Linux 上:shutdown.sh
On Windows: shutdown.bat
在 Windows 上:shutdown.bat
回答by Pratik Agarwal
Create a .bat
file and write two commands:
创建一个.bat
文件,写两个命令:
cd C:\ Path to your tomcat directory \ bin
startup.bat
Now on double-click, Tomcat server will start.
现在双击,Tomcat 服务器将启动。
回答by Yuvi Jum
Steps to start Apache Tomcat using cmd:
1. Firstly check that the JRE_HOME or JAVA_HOME is a variable available in environment variables.(If it is not create a new variable JRE_HOME or JAVA_HOME)
2. Goto cmd and change your working directory to bin path where apache is installed (or extracted).
3. Type Command -> catalina.bat start
to startthe server.
4. Type Command -> catalina.bat stop
to stopthe server.
使用cmd启动Apache Tomcat的步骤:
1.首先检查JRE_HOME或JAVA_HOME是否是环境变量中可用的变量。(如果不是创建一个新的变量JRE_HOME或JAVA_HOME)
2.进入cmd,将你的工作目录更改为bin路径安装(或提取)apache 的位置。
3. 键入 Command ->catalina.bat start
以启动服务器。
4.键入命令- >catalina.bat stop
到停止服务器。
回答by фымышонок
I have just downloaded Tomcat and want to stop it (Windows).
我刚刚下载了 Tomcat 并想停止它(Windows)。
To stop tomcat
run cmd as administrator (I used Cmder)
find process ID
停止tomcat
以管理员身份运行 cmd(我使用了 Cmder)
查找进程 ID
tasklist /fi "Imagename eq tomcat*"
tasklist /fi "Imagename eq tomcat*"
C:\Users\Admin
tasklist /fi "Imagename eq tomcat*"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
Tomcat8aaw.exe 6376 Console 1 7,300 K
Tomcat8aa.exe 5352 Services 0 124,748 K
- stop prosess with pid 6376
- 使用 pid 6376 停止进程
C:\Users\Admin
C:\用户\管理员
taskkill /f /pid 6376
SUCCESS: The process with PID 6376 has been terminated.
成功:PID 为 6376 的进程已终止。
- stop process with pid 5352
- 使用 pid 5352 停止进程
C:\Users\Admin
C:\用户\管理员
taskkill /f /pid 5352
SUCCESS: The process with PID 5352 has been terminated.
成功:PID 为 5352 的进程已终止。