使用 Eclipse 调试 Java Service Fabric 应用程序Debug your Java Service Fabric application using Eclipse

  1. 按照设置 Service Fabric 开发环境中的步骤启动本地开发群集。Start a local development cluster by following the steps in Setting up your Service Fabric development environment.

  2. 更新要调试的服务的 entryPoint.sh,以便使用远程调试参数启动 java 进程。Update entryPoint.sh of the service you wish to debug, so that it starts the java process with remote debug parameters. 可以在以下位置找到此文件:ApplicationName\ServiceNamePkg\Code\entrypoint.shThis file can be found at the following location: ApplicationName\ServiceNamePkg\Code\entrypoint.sh. 在此示例中调试时,设置端口 8001。Port 8001 is set for debugging in this example.

    java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n -Djava.library.path=$LD_LIBRARY_PATH -jar myapp.jar
    
  3. 通过将要调试的服务的实例计数或副本计数设置为 1 来更新应用程序清单。Update the Application Manifest by setting the instance count or the replica count for the service that is being debugged to 1. 此设置可避免用于调试的端口出现冲突。This setting avoids conflicts for the port that is used for debugging. 例如,对于无状态服务,设置 InstanceCount="1";对于有状态服务,将目标和最小副本集大小设置为 1,如下所示:TargetReplicaSetSize="1" MinReplicaSetSize="1"For example, for stateless services, set InstanceCount="1" and for stateful services set the target and min replica set sizes to 1 as follows: TargetReplicaSetSize="1" MinReplicaSetSize="1".

  4. 部署应用程序。Deploy the application.

  5. 在 Eclipse IDE 中,选择“运行”->“调试配置”->“远程 Java 应用程序和输入连接属性” ,并按如下所示设置属性:In the Eclipse IDE, select Run -> Debug Configurations -> Remote Java Application and input connection properties and set the properties as follows:

    Host: ipaddress
    Port: 8001
    
  6. 在所需的位置设置断点并调试应用程序。Set breakpoints at desired points and debug the application.

如果应用程序崩溃,可能还想要启用 coredumps。If the application is crashing, you may also want to enable coredumps. 在 shell 中执行 ulimit -c,如果它返回 0,则未启用 coredumps。Execute ulimit -c in a shell and if it returns 0, then coredumps are not enabled. 若要启用不受限制的 coredumps,请执行以下命令:ulimit -c unlimitedTo enable unlimited coredumps, execute the following command: ulimit -c unlimited. 还可以使用命令 ulimit -a 验证状态。You can also verify the status using the command ulimit -a. 如果要更新 coredump 生成路径,请执行 echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_patternIf you wanted to update the coredump generation path, execute echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern.

后续步骤Next steps