在 Eclipse 中调试 Playframework
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7172013/
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
Debug Playframework in Eclipse
提问by Thang Nguyen
I just moved from Netbeans to Eclipse. In Netbeans, I can debug Playframework applications out of the box. However, in Eclipse, it seems hard to configure this in order to debug a web app (a Playframework app in specific).
我刚刚从 Netbeans 转移到 Eclipse。在 Netbeans 中,我可以开箱即用地调试 Playframework 应用程序。但是,在 Eclipse 中,为了调试 Web 应用程序(特别是 Playframework 应用程序)而对其进行配置似乎很困难。
As in Play! documentation,
就像在玩一样!文件,
The main launcher in only usable with the Run As eclipse command. You can then use the “Connect JPDA launcher” using “Debug As” to start a debugging session at any time. Stopping the debugging session will not stop the server.
主启动器只能与 Run As eclipse 命令一起使用。然后,您可以使用“连接 JPDA 启动器”和“调试方式”随时启动调试会话。停止调试会话不会停止服务器。
However, I can not see “Connect JPDA launcher” in "Debug As" (I'm using Eclipse Classic 3.7.0). I've searched about JPDA (I'm new to Java and don't know about "main launcher" and JPDA, then config Remote Debug as instruct in http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.htmlBut it's returning an error:
但是,我在“Debug As”中看不到“Connect JPDA launcher”(我使用的是 Eclipse Classic 3.7.0)。我搜索过 JPDA(我是 Java 新手,不知道“主启动器”和 JPDA,然后按照http://javarevisited.blogspot.com/2011/02/how-to 中的说明配置远程调试 -setup-remote-debugging-in.html但它返回一个错误:
Failed to connect to remote VM. Connection refused. Connection refused: connect
无法连接到远程 VM。拒绝连接。连接被拒绝:连接
I've searched and found some suggestions like:
我搜索并找到了一些建议,例如:
1.)editing catalina.bat and adding the lines : set JPDA_TRANSPORT=dt_socket ... set JPDA_ADDRESS=8000 AND 2.)Editing startup.bat call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
1.) 编辑 catalina.bat 并添加行:set JPDA_TRANSPORT=dt_socket ... set JPDA_ADDRESS=8000 AND 2.)Editing startup.bat call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Actually I don't clearly understand this and I guess it's for configuring Tomcat. However, I'm using Play! default server, checked the application.conf and sure that it's listening to port 9000 and 8000 for JPDA.
其实我不是很明白这个,我猜是为了配置Tomcat。但是,我正在使用 Play!默认服务器,检查 application.conf 并确保它正在侦听 JPDA 的 9000 和 8000 端口。
Of course, I have started the Play app before debugging, I can access the app via port 9000 normally. I'm using Win 7 with no admin rights.
当然,我在调试之前已经启动了 Play 应用程序,我可以通过端口 9000 正常访问该应用程序。我正在使用没有管理员权限的 Win 7。
Do you have a detailed guide on debugging Play! in Eclipse?
你有详细的调试指南吗?在 Eclipse 中?
采纳答案by Tommi
First of all, you have created the configuration files for Eclipse by using the play eclipsify YourProject
command, right? (If not, see Play framework documentationfor more information.)
首先,您已经通过play eclipsify YourProject
命令创建了Eclipse的配置文件,对吗?(如果没有,请参阅Play 框架文档以获取更多信息。)
After that, you should have a folder named eclipse
in your project. In it, you should see commands Connect JDPA to YourProject.launch
, YourProject.launch
and Test YourProject.launch
.
之后,您的项目中应该有一个命名的文件夹eclipse
。在其中,您应该看到命令Connect JDPA to YourProject.launch
、YourProject.launch
和Test YourProject.launch
。
Right-click on the YourProject.launch
and choose Run As --> YourProject
from the pop-up menu. That will start your application. When the application is running, right-click on the Connect JDPA to YourProject.launch
, and choose Debug As --> Connect JDPA to YourProject.launch
from the pop-up menu. That will start a debug session on your application.
右键单击YourProject.launch
并Run As --> YourProject
从弹出菜单中选择。这将启动您的应用程序。当应用程序运行时,右键单击Connect JDPA to YourProject.launch
,然后Debug As --> Connect JDPA to YourProject.launch
从弹出菜单中选择。这将在您的应用程序上启动调试会话。
回答by Mansoor Siddiqui
As of Play 2.0, the eclipse
folder and launchers are no longer generated when you run play eclipsify
. After running play eclipsify
, you can debug your project in Eclipse as follows:
从 Play 2.0 开始,eclipse
运行play eclipsify
. 运行后play eclipsify
,您可以在 Eclipse 中调试您的项目,如下所示:
- In a console outside of eclipse, run
play debug run
. - In Eclipse, right-click your project, then choose
Debug As -> Debug Configurations...
- Right-click
Remote Java Application
, then clickNew
. - The host should already be set to
localhost
. Set the port to9999
(the default port used by theplay debug run
command). - Click
Apply
to save, thenDebug
to connect to your running Play instance.
- 在 eclipse 之外的控制台中,运行
play debug run
. - 在 Eclipse 中,右键单击您的项目,然后选择
Debug As -> Debug Configurations...
- 右键单击
Remote Java Application
,然后单击New
。 - 主机应该已经设置为
localhost
。将端口设置为9999
(play debug run
命令使用的默认端口)。 - 单击
Apply
以保存,然后Debug
连接到您正在运行的 Play 实例。
回答by user1997292
Play 2.1-RC2 :Running Play! app that is synced with Eclipse
播放 2.1-RC2 :运行播放!与 Eclipse 同步的应用程序
To make the project Eclipse compatible, got he project folder and then give command ">play eclipse". Now you can add it as an existing project form eclipse.
为了使项目 Eclipse 兼容,获取他的项目文件夹,然后给出命令“>play eclipse”。现在您可以将其添加为现有项目表单 eclipse。
Then to run it you have to first run start play in the project folder i.e. command "play"
然后要运行它,您必须首先在项目文件夹中运行开始播放,即命令“播放”
This will activate play server and identify the app in the project i.e. [appname]$ now you have to just give the command "run" to see your app running on the localhost:9000 or whichever port config you have specified.
这将激活播放服务器并识别项目中的应用程序,即 [appname]$ 现在您只需给出命令“运行”即可查看您的应用程序在 localhost:9000 或您指定的任何端口配置上运行。
Debug mode:To run this similarly you need first give command "play" then [appname]$ "play debug run" this will by default use port 9999 so when you go to localhost:9000 in your browser and in your eclipse file -> Debug As -> Debug configuration.. -> New Remote Java Application -> connect specify port 9999 and debug
调试模式:要类似地运行它,您需要首先给出命令“play”然后[appname]$“play debug run”这将默认使用端口9999,因此当您在浏览器和eclipse文件中转到localhost:9000时-> Debug As -> Debug configuration.. -> New Remote Java Application -> connect 指定端口 9999 并调试
回答by 0fnt
With activator, you'll need activator -jvm-debug <port number> ~run
使用活化剂,您需要 activator -jvm-debug <port number> ~run
回答by Sagiruddin Mondal
I guess most of you are running the play framework with Typesafe Activator. If you are doing so, This may help you,
我想你们中的大多数人都在使用 Typesafe Activator 运行 play 框架。如果你这样做,这可能会帮助你,
activator -jvm-debug ~run
Like : activator -jvm-debug 9999~run
激活器 -jvm-debug ~run
喜欢:activator -jvm-debug 9999~run
(then It will start the debugger in 9999 port along with the app running in 9000 port.)
(然后它将在 9999 端口启动调试器以及在 9000 端口运行的应用程序。)
- Now go to eclipse and right click on the project name you want to debug and select Debug As-> Debug configuration.. -> (select)Remote Java Application -> new (top left an icon with tiny plus sign) -> connect specify port 9999 and debug.
- 现在转到 eclipse 并右键单击要调试的项目名称并选择 Debug As-> Debug configuration.. -> (select)Remote Java Application -> new (左上角一个带有小加号的图标) -> connect 指定端口 9999 和调试。
回答by IanRae
As of Play 2.1.2, I was getting the 'address in use' error when running play debug run.
从 Play 2.1.2 开始,我在运行 play debug run 时收到“正在使用的地址”错误。
The fix was to edit play.bat in play-2.1.2 directory and change these two lines:
修复是在 play-2.1.2 目录中编辑 play.bat 并更改这两行:
:setDebug
set JPDA_PORT=9999
to
到
:setDebug
set JPDA_PORT=8551
Then in Eclipse, select Debug Configurations, find "Remote Java Application", do New. Then set port to 8551. Now you can start play using
然后在 Eclipse 中,选择 Debug Configurations,找到“Remote Java Application”,执行 New。然后将端口设置为 8551。现在您可以使用
play debug run
And then in Eclipse start debugging using the debug configuration you created about.
然后在 Eclipse 中使用您创建的调试配置开始调试。
回答by javierhe
If you run "play eclipsify" on the project folder, it will create two run configurations. Looking at the run configuration details, you should check if the following line (or something similar) is in the "VM arguments":
如果您在项目文件夹上运行“play eclipsify”,它将创建两个运行配置。查看运行配置详细信息,您应该检查以下行(或类似内容)是否在“VM 参数”中:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Dplay.debug=yes
-Dplay.id=test -Dapplication.path="${project_loc:NMKServer}"
-Djava.endorsed.dirs="c:\Java\play-1.2.2/framework/endorsed"
-javaagent:"c:\Java\play-1.2.2/framework/play-1.2.2.jar"
Here you can configure the debugging port. With this config, I can attach to process using the instructuctions you have.
在这里可以配置调试端口。使用此配置,我可以使用您拥有的说明附加到进程。