简体   繁体   English

Bluemix CF Java buildpack应用程序的远程调试

[英]Remote debugging of Bluemix CF Java buildpack application

I have a standalone java application deployed on IBM Bluemix as Cloud Foundry Java buildpack. 我有一个作为Cloud Foundry Java buildpack部署在IBM Bluemix上的独立Java应用程序。

Is there a way to perform remote debugging on it in Eclipse?I could find only docs for remote debugging of Java Liberty buildpack applications. 是否可以在Eclipse中对其执行远程调试?我只能找到用于Java Liberty buildpack应用程序的远程调试的文档。

The socket listen way mentioned in the other answer is certainly convenient, but expects you to have a public IP assigned to your debug machine(or you have to configure some port forwarding on your router). 在另一个答案中提到的套接字侦听方式当然很方便,但是希望您将一个公共IP分配给调试机(或者必须在路由器上配置一些端口转发)。 This might not always be possible. 这可能并不总是可能的。

So the another way to do it is enable debugging on your Java app and use ssh port forwarding to connect to the app instance. 因此,另一种方法是在Java应用程序上启用调试,并使用ssh端口转发连接到应用程序实例。 Following are the steps 以下是步骤

  1. Enable java debugging by setting environment variable JBP_CONFIG_DEBUG with value {enabled: true} and restarting the application. 通过将环境变量JBP_CONFIG_DEBUG设置为值{enabled: true}并重新启动应用程序来启用Java调试。
  2. Set up the SSH tunnel for the debug framework via JDWP 通过JDWP为调试框架设置SSH隧道

    cf ssh -N -T -L 8000:localhost:8000 <APP_NAME>

  3. After the ssh tunnel is opened, you use the Socket Attach debug type from eclipse on localhost:8000 打开ssh隧道后,您可以在localhost:8000上使用来自eclipse的套接字附加调试类型

Prerequisites before cf ssh : cf api , cf login , cf target cf ssh之前的先决条件: cf apicf logincf target

There are some instructions in the Java buildpack documentation at https://docs.cloudfoundry.org/buildpacks/java/java-tips.html#debugging Java buildpack文档中有一些说明, 网址https://docs.cloudfoundry.org/buildpacks/java/java-tips.html#debugging

  1. Open your project in Eclipse. 在Eclipse中打开您的项目。
  2. Right-click on your project, go to Debug as and pick Debug Configurations. 右键单击项目,转到“调试为”,然后选择“调试配置”。
  3. Create a new Remote Java Application. 创建一个新的远程Java应用程序。
  4. Make sure your project is selected, pick Standard (Socket Listen) from the Connection Type drop down and set a port. 确保选择了您的项目,从“连接类型”下拉列表中选择“标准(侦听套接字)”并设置端口。 Make sure this port is open if you are running a firewall. 如果您正在运行防火墙,请确保此端口是打开的。
  5. Click Debug. 单击调试。

The debugger should now be running. 调试器现在应该正在运行。 If you switch to the Debug perspective, you should see your application listed in the Debug panel and it should say Waiting for vm to connect at port . 如果切换到“调试”透视图,则应在“调试”面板中看到您的应用程序,并且应显示“ Waiting for vm to connect at port

Next, push your application to Cloud Foundry and instruct Cloud Foundry to connect to the debugger running on your local machine using the following instructions: 接下来,使用以下说明将应用程序推送到Cloud Foundry并指示Cloud Foundry连接到在本地计算机上运行的调试器:

  1. Edit your manifest.yml file. 编辑您的manifest.yml文件。 Set the instances count to 1. If you set this greater than one, multiple applications try to connect to your debugger. 将实例计数设置为1。如果将此值设置为大于1,则多个应用程序尝试连接到调试器。
  2. Also in manifest.yml, add the env section and create a variable called JAVA_OPTS. 同样在manifest.yml中,添加env部分并创建一个名为JAVA_OPTS的变量。
  3. Add the remote debugger configuration to the JAVA_OPTS variable: -agentlib:jdwp=transport=dt_socket,address=YOUR-IP-ADDRESS:YOUR-PORT . 将远程调试器配置添加到JAVA_OPTS变量: -agentlib:jdwp=transport=dt_socket,address=YOUR-IP-ADDRESS:YOUR-PORT
  4. Save the manifest.yml file. 保存manifest.yml文件。
  5. Run cf push. 运行cf push。

Upon completion, you should see that your application has started and is now connected to the debugger running in your IDE. 完成后,您应该看到您的应用程序已启动,并且现在已连接到在IDE中运行的调试器。 You can now add breakpoints and interrogate the application just as you would if it were running locally. 现在,您可以添加断点并查询应用程序,就像在本地运行该应用程序一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM