使用 m2eclipse 开发 Web 应用程序的首选方式

发布于 2024-08-06 13:24:53 字数 310 浏览 6 评论 0原文

在开发 Maven Web 应用程序时,我通常使用 jetty-maven-plugin 来快速启动我的应用程序以进行本地测试和调试。使用 m2eclipse 启动的缺点是无法正确包含所有调试源,即使它们是由 Maven 下载的(请参阅 源查找似乎不起作用)。

在 Eclipse 中调试 Maven Web 应用程序的首选方法是什么?我特别欣赏与 gwt-maven-plugin 一起使用的配置。

When developing Maven web applications I usually resort the the jetty-maven-plugin to quickly launch my application for local testing and debugging. Using the launch with m2eclipse has the drawback of not properly including all sources for debugging, even though they are downloaded by Maven ( see Source lookup does not seem to work ).

What is the preferred way to debug Maven web applications in Eclipse? I'd especially appreciate configurations which work with the gwt-maven-plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眼泪 2024-08-13 13:24:53

我使用 m2eclipse 开发 Web 应用程序的首选方法是...不使用它。相反,我使用 中描述的方法在 Eclipse 中使用 Maven Jetty 插件进行调试,我在下面引用:

第 1 步

转到运行/外部工具/外部
“运行”菜单上的“工具...”菜单项
酒吧。选择“程序”并单击
“新建”按钮。在“主要”选项卡上,填写
在“位置:”中作为完整路径
您的“mvn”可执行文件。对于
“工作目录:”选择
与您的网络应用程序匹配的工作区。
对于“参数:”添加 jetty:run

移至“环境”选项卡并
单击“新建”按钮添加新的
名为 MAVEN_OPTS 的变量
值:

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

如果您提供 suspend=n 而不是
suspend=y 您可以立即开始
不运行调试器并且
随时启动调试器
真的很想调试。

第 2 步

然后,拉出“运行/调试/调试
...”菜单项并选择“远程 Java
应用程序”,然后单击“新建”
按钮。填写对话框
选择您的 webapp 项目
“项目:”字段,并确保您是
使用与您相同的端口号
address= 属性中指定
如上所述。

现在你需要做的就是
运行/外部工具并选择名称
您创建的 Maven 工具设置
步骤 1 启动插件,然后
运行/调试并选择名称
调试您在步骤 2 中设置的设置。

来自提供的说明
Rolf Strijdhorst 谈 Maven 邮件
列表

停止码头

为了停止jetty服务器
“允许终止远程虚拟机”
应该在调试对话框中检查
第2步.当你拥有jetty服务器时
正在运行并且调试器连接了你
可以切换到调试视角。
在调试视图中,右键单击
Java HotSpot(TM) 客户端
VM[localhost:4000] 并选择
终止。这将停止调试器
和码头服务器。

My preferred way to develop web applications with m2eclipse is to... not use it. Instead, I use the approach described in Debugging with the Maven Jetty Plugin in Eclipse that I'm quoting below:

Step 1

Go to the Run/External Tools/External
Tools ..." menu item on the "Run" menu
bar. Select "Program" and click the
"New" button. On the "Main" tab, fill
in the "Location:" as the full path to
your "mvn" executable. For the
"Working Directory:" select the
workspace that matches your webapp.
For "Arguments:" add jetty:run.

Move to the "Environment" tab and
click the "New" button to add a new
variable named MAVEN_OPTS with the
value:

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

If you supply suspend=n instead of
suspend=y you can start immediately
without running the debugger and
launch the debugger at anytime you
really wish to debug.

Step 2

Then, pull up the "Run/Debug/Debug
..." menu item and select "Remote Java
Application" and click the "New"
button. Fill in the dialog by
selecting your webapp project for the
"Project:" field, and ensure you are
using the same port number as you
specified in the address= property
above.

Now all you need to do is to
Run/External Tools and select the name
of the maven tool setup you created in
step 1 to start the plugin and then
Run/Debug and select the name of the
debug setup you setup in step2.

From instructions provided by
Rolf Strijdhorst on the Maven mailing
list

Stopping Jetty

In order to stop the jetty server the
"Allow termination of remote VM"
should be checked in debug dialog in
Step 2. When you have the jetty server
running and the debugger connected you
can switch to the debug perspective.
In the debug view, right click on the
Java HotSpot(TM) Client
VM[localhost:4000] and chose
terminate. This will stop the debugger
and the jetty server.

陈独秀 2024-08-13 13:24:53

尽量避免编写需要某种容器来调试的代码。始终编​​写可以独立运行的代码,并将其包装在非常薄的层中进行部署(薄层 -> 几行代码 -> 很少的错误)。

如果您确实必须这样做,请尝试 MockRunner 来模拟应用服务器。

除此之外,您可以在项目属性中手动添加源。

Try to avoid writing code which needs a container of some kind to debug. Always write code that can run independently and wrap it in a very thin layer for deployment (thin layer -> few lines of code -> few bugs).

If you really must, try MockRunner to emulate the app server.

Other than that, you can manually add the sources in the project properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文