简体   繁体   English

如何从 apache tomcat 服务器的命令提示符启动调试模式?

[英]How to start debug mode from command prompt for apache tomcat server?

I want to start debug mode for my application.我想为我的应用程序启动调试模式。 But I need to start the debug mode from command prompt.但我需要从命令提示符启动调试模式。 Is it possible ?是否有可能 ? And will the procedure vary between tomcat 5.5 to tomcat 6.?并且程序会在 tomcat 5.5 到 tomcat 6 之间有所不同吗?

On windows 在窗户上
$ catalina.bat jpda start
On Linux/Unix 在 Linux/Unix 上
$ catalina.sh jpda start

More info ----> https://cwiki.apache.org/confluence/display/TOMCAT/Developing更多信息----> https://cwiki.apache.org/confluence/display/TOMCAT/Developing

For windows first set variables:对于 Windows,首先设置变量:

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

to start server in debug mode:在调试模式下启动服务器:

%TOMCAT_HOME%/bin/catalina.bat jpda start

For unix first export variables:对于 unix 第一个导出变量:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

and to start server in debug mode:并以调试模式启动服务器:

%TOMCAT_HOME%/bin/catalina.sh jpda start
  1. From your IDE, create a remote debug configuration, configure it for the default JPDA Tomcat port which is port 8000.在您的 IDE 中,创建一个远程调试配置,将其配置为默认的 JPDA Tomcat 端口,即端口 8000。

  2. From the command line:从命令行:

    Linux: Linux:

     cd apache-tomcat/bin export JPDA_SUSPEND=y ./catalina.sh jpda run

    Windows:视窗:

     cd apache-tomcat\\bin set JPDA_SUSPEND=y catalina.bat jpda run
  3. Execute the remote debug configuration from your IDE, and Tomcat will start running and you are now able to set breakpoints in the IDE.从您的 IDE 执行远程调试配置,Tomcat 将开始运行,您现在可以在 IDE 中设置断点。

Note:笔记:

The JPDA_SUSPEND=y line is optional, it is useful if you want that Apache Tomcat doesn't start its execution until step 3 is completed, useful if you want to troubleshoot application initialization issues. JPDA_SUSPEND=y行是可选的,如果您希望 Apache Tomcat 在第 3 步完成之前不开始执行,它很有用,如果您想对应用程序初始化问题进行故障排除,则很有用。

简短的回答是在 JVM 启动时添加以下选项。

JAVA_OPTS=" $JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8080"

First, Navigate to the TOMCAT-HOME/bin directory.首先,导航到TOMCAT-HOME/bin目录。

Then, Execute the following in the command-line:然后,在命令行中执行以下命令:

catalina.bat jpda start

If the Tomcat server is running under Linux, just invoke the catalina.sh program如果Tomcat服务器运行在Linux下,调用catalina.sh程序即可

catalina.sh jpda start

It's the same for Tomcat 5.5 and Tomcat 6 Tomcat 5.5 和 Tomcat 6 是一样的

These instructions worked for me on apache-tomcat-8.5.20 on mac os 10.13.3 using jdk1.8.0_152:这些说明在使用 jdk1.8.0_152 的 mac os 10.13.3 上的 apache-tomcat-8.5.20 上对我有用:

$ cd /path/to/apache-tomcat-8.5.20/bin
$ export JPDA_ADDRESS="localhost:12321"
$ ./catalina.sh jpda run

Now connect to port 12321 from IntelliJ/Eclipse and enjoy remote debugging.现在从 IntelliJ/Eclipse 连接到端口 12321 并享受远程调试。

There are two ways to run tomcat in debug mode在调试模式下运行tomcat有两种方式

  1. Using jdpa run使用 jdpa 运行

  2. Using JAVA_OPTS使用 JAVA_OPTS

First setup the environment.首先设置环境。 Then start the server using following commands.然后使用以下命令启动服务器。

 export JPDA_ADDRESS=8000 export JPDA_TRANSPORT=dt_socket %TOMCAT_HOME%/bin/catalina.sh jpda start sudo catalina.sh jpda start

refer this article for more information this is clearly define it请参阅本文以获取更多信息,这是明确定义的

If you're wanting to do this via powershell on windows this worked for me如果您想通过 Windows 上的 powershell 执行此操作,这对我有用

$env:JPDA_SUSPEND="y" $env:JPDA_SUSPEND="y"

$env:JPDA_TRANSPORT="dt_socket" $env:JPDA_TRANSPORT="dt_socket"

/path/to/tomcat/bin/catalina.bat jpda start /path/to/tomcat/bin/catalina.bat jpda start

Inside catalina.bat set the port on which you wish to start the debugger在 catalina.bat 中设置您希望启动调试器的端口

if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=9001

Then you can simply start the debugger with然后你可以简单地启动调试器

catalina.bat jpda 

Now from Eclipse or IDEA select remote debugging and start start debugging by connecting to port 9001.现在从 Eclipse 或 IDEA 中选择远程调试并通过连接到端口 9001 开始调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM