使用 maven tomcat 和 eclipse 进行远程调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20703274/
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
remote debugging with maven tomcat and eclipse
提问by TPPZ
The same "old question", I am pretty new to Maven and I can not figure out why in the end I am getting a message like "Failed to connect to remote VM. Connection refused." from Eclipse.
同样的“老问题”,我对 Maven 还很陌生,我不明白为什么最后我会收到“无法连接到远程 VM。连接被拒绝”这样的消息。来自日食。
Maven options (I've set this environment variable on my ~/.profile
~/.bashrc
etc.)
Maven 选项(我已经在我的~/.profile
~/.bashrc
等设备上设置了这个环境变量)
$ echo $MAVEN_OPTS
-Xmx1024m -Xms256m -XX:MaxPermSize=256m -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
On Eclipse I've set a Debug profile on a Remote Java Application
based on the project I want to debug, with host 127.0.0.1
(not localhost
because the Maven profile dev
I am using, see below, is explicitly setting that IP address) and port 8000
.
在 Eclipse 上,我Remote Java Application
根据我要调试的项目设置了一个调试配置文件,使用主机127.0.0.1
(不是localhost
因为dev
我使用的 Maven 配置文件,见下文,明确设置了该 IP 地址)和端口8000
。
Then when I run the application from the command line with the following command (maven is picking a dev
profile from the pom file):
然后,当我使用以下命令从命令行运行应用程序时(maven 正在dev
从 pom 文件中选择一个配置文件):
$ mvn tomcat:run -P dev
and I start Eclipse in debug mode on the Eclipse Remote Java Application profile I previously set I am getting a message from an Eclipse popup window saying:
我在之前设置的 Eclipse 远程 Java 应用程序配置文件上以调试模式启动 Eclipse 我从 Eclipse 弹出窗口收到一条消息:
Failed to connect to remote VM. Connection refused.
Connection refused
I suspect the settings from the $MAVEN_OPTS
are not pick up from some reason, have a look at the following output from the ps
command:
我怀疑由于$MAVEN_OPTS
某种原因没有启动设置,请查看ps
命令的以下输出:
USER_NAME@my-laptop $ ps aux | grep tomcat
USER_NAME 16526 11.3 13.7 3014276 500680 pts/5 Sl+ 11:25 0:29 /usr/lib/jvm/java-7-openjdk-amd64/bin/java -classpath /usr/share/maven/boot/plexus-classworlds-2.x.jar -Dclassworlds.conf=/usr/share/maven/bin/m2.conf -Dmaven.home=/usr/share/maven org.codehaus.plexus.classworlds.launcher.Launcher tomcat:run -P dev
More details:
更多细节:
- java version "1.7.0_25"
- OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
- OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
- Eclipse Kepler
- java版本“1.7.0_25”
- OpenJDK 运行时环境 (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
- OpenJDK 64 位服务器 VM(构建 23.7-b01,混合模式)
- 日食开普勒
Please shed some light, thanks and again... Apologies for the dummy question.
请阐明,再次感谢... 为这个虚拟问题道歉。
回答by Richard Neish
The docs for tomcat:rundescribe the systemProperties value that you can put in the pom.xml file.
tomcat:run的文档描述了可以放入 pom.xml 文件的 systemProperties 值。
The settings that you have above would look like this in your pom.xml:
你上面的设置在你的 pom.xml 中看起来像这样:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.2-SNAPSHOT</version>
<configuration>
<systemProperties>
<JAVA_OPTS>-Xmx1024m -Xms256m -XX:MaxPermSize=256m -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000</JAVA_OPTS>
</systemProperties>
</configuration>
Also, see this answer.
另外,请参阅此答案。
回答by Pieter
It looks like you are missing a parameter, try adding -Xdebug
to your MAVEN_OPTS
看起来您缺少一个参数,请尝试添加-Xdebug
到您的 MAVEN_OPTS