Java 在 ubuntu-server 中为 Tomcat7 设置 JPDA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19578851/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:28:54  来源:igfitidea点击:

Setting up JPDA for Tomcat7 in ubuntu-server

javaeclipsetomcatubuntutomcat7

提问by Ospho

I am attempting to setup the JPDA for Tomcat7 in ubuntu.
I have used the apt-get method of installing Tomcat7.
By attempting to edit the /usr/share/tomcat7/startup.sh file with the following lines I try to get tomcat7 to boot into debug mode and allow remote debugging via eclipse.

我正在尝试在 ubuntu 中为 Tomcat7 设置 JPDA。
我已经使用了安装Tomcat7的apt-get方法。
通过尝试使用以下几行编辑 /usr/share/tomcat7/startup.sh 文件,我尝试让 tomcat7 启动到调试模式并允许通过 eclipse 进行远程调试。

 JPDA_TRANSPORT="dt_socket"
 JPDA_ADDRESS="8000"
 exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

After editing the startup.sh file, I reboot tomcat7 using:

编辑 startup.sh 文件后,我使用以下命令重新启动 tomcat7:

 sudo service tomcat7 restart

Then attempt to connect to the tomcat jpda in eclipse with the IP address and port 8000. I receive a "Connection Refused" error from Eclipse.

然后尝试使用 IP 地址和端口 8000 连接到 eclipse 中的 tomcat jpda。我收到来自 Eclipse 的“连接被拒绝”错误。

I have attempted to manually start tomcat7 using the startup.sh script rather than the service executable method as I thought perhaps the startup.sh was not being called.

我尝试使用 startup.sh 脚本而不是服务可执行方法手动启动 tomcat7,因为我认为可能没有调用 startup.sh。

sudo ./startup.sh

This failed with the following output:

这失败了,输出如下:

 Using CATALINA_BASE:   /usr/share/tomcat7
 Using CATALINA_HOME:   /usr/share/tomcat7
 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
 Using JRE_HOME:        /usr
 Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
 touch: cannot touch `/usr/share/tomcat7/logs/catalina.out': No such file or directory
 ./catalina.sh: 389: ./catalina.sh: cannot create /usr/share/tomcat7/logs/catalina.out: Directory nonexistent

I have also attempted to alter the startup script at /etc/init.d/tomcat7 as I am using service to start/restart tomcat7 to no avail...

我还尝试更改 /etc/init.d/tomcat7 中的启动脚本,因为我正在使用服务来启动/重新启动 tomcat7 无济于事...

What am I doing wrong?

我究竟做错了什么?

采纳答案by David Levesque

In Ubuntu 12.04+ there is a section like this in /etc/default/tomcat7:

在 Ubuntu 12.04+ 中有这样一个部分/etc/default/tomcat7

# To enable remote debugging uncomment the following line.
# You will then be able to use a java debugger on port 8000.
#JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

So just uncomment it and run sudo service tomcat7 restart.

所以只需取消注释并运行sudo service tomcat7 restart

回答by Jai

Settings required in Tomcat:

Tomcat 中需要的设置:

1)Create setenv.sh file under */tomcat/bin/. The location will be same as the catalina.sh file

1)在*/tomcat/bin/下创建setenv.sh文件。该位置将与 catalina.sh 文件相同

2)Place the below content inside it.

2)将以下内容放入其中。

export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n" Now start the Tomcat server. Once it is started please proceed with the below steps.

export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n" 现在启动Tomcat服务器。启动后,请继续执行以下步骤。

Settings required in Eclipse:

Eclipse 中所需的设置:

3)In Eclipse go to Windows-->Preference--> General-->Network Connection --> Active Provider should be Direct. After changing to direct restart the eclipse.

3) 在 Eclipse 中,转到 Windows--> 首选项--> 常规--> 网络连接--> Active Provider 应该是 Direct。改完后直接重启eclipse。

4)In eclipse right click on project and debug as ->debug configuration ->Remote java application ->Create new configuration.

4)在eclipse中右键单击项目并调试为->调试配置->远程java应用程序->创建新配置。

Fill the below fields

填写以下字段

Name: as your wish

名称:如你所愿

Project: Select the project which you need to debug.

项目:选择需要调试的项目。

ConnectionType: Standard socket attach

连接类型:标准插座连接

Host: Localhost Port: 8000(It should be same as mentioned in point 2)

主机:Localhost 端口:8000(应该和第2点提到的一样)

Then click debug.

然后点击调试。

The debug will start at port 8000. Now you can verify by keeping breakpoints.

调试将从端口 8000 开始。现在您可以通过保留断点来验证。