使用 Eclipse 和 Maven 调试打包为 WAR 的 Java Web 应用程序的最佳方法? [英] Best way to debug Java web application packaged as a WAR using Eclipse and Maven?

查看:29
本文介绍了使用 Eclipse 和 Maven 调试打包为 WAR 的 Java Web 应用程序的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前没有构建过 Java Web 应用程序,但我已经完成了足够的测试,并且 Maven 正在构建我的 WAR 文件就好了.它是一个多模块的 Maven 项目,依赖的模块在 WAR 的 WEB-INF/lib 目录中都有它们的 JAR 文件.

I've not built a Java web application before, but I have it complete enough to test and Maven is building my WAR file just fine. It is a multi-module Maven project and the dependent modules all have their JAR files in the WEB-INF/lib directory of the WAR.

所以一切看起来都很好,但是如何调试呢?我知道如何(从命令行)在我的机器上的 Tomcat 中运行 WAR.我还认为我知道如何从命令行设置和运行 Maven Jetty 插件.但是如何最好地调试...使用我喜欢的 Eclipse 的所有断点和变量检查?

So everything seems fine, but how to debug? I know how to (from the command line) run the WAR in Tomcat on my machine. I also think I know how to set up and run the Maven Jetty plugin from the command line as well. But how best to debug...with all the break points and variable inspection I love with Eclipse?

我应该创建某种启动配置,还是远程连接调试器?Eclipse 中有什么东西可以提供帮助……比如插件?

Is there some kind of launch configuration I should create, or do I attach the debugger remotely? Is there something in Eclipse that can help...like a plugin?

推荐答案

如果您使用 tomcat/jetty 插件运行 WAR,请将调试选项传递给 Maven:

If you run your WAR with tomcat/jetty plugin pass debug options to the Maven:

export MAVEN_OPTS="-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" mvn tomcat:run

如果您使用常规 Tomcat 运行 WAR,只需在启用 JPDA(调试器)支持的情况下运行它:

If you run your WAR using the regular Tomcat, just run it with JPDA (debugger) support enabled:

$TOMCAT_HOME/bin/catalina.sh jpda start

Tomcat 6 JPDA 的默认端口是 8000.

Default port for Tomcat 6 JPDA is 8000.

现在将 Eclipse(调试 -> 远程 Java 应用程序)连接到端口 8000 并享受您的调试会话.

Now connect with the Eclipse (Debug -> Remote Java Application) to the port 8000 and enjoy your fine debugging session.

这篇关于使用 Eclipse 和 Maven 调试打包为 WAR 的 Java Web 应用程序的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆