Jef*_*fLL 91 java eclipse debugging spring spring-boot
我的Spring Bootwebapp运行得很好,我想通过Eclipse调试它.
因此,在启动我的远程Java应用程序调试器时,我应该收听哪个端口?我的webapp上有一个设置我必须设置为启用调试吗?
Dav*_*yer 155
你为什么不直接点击main()方法并选择"Debug As... Java Application"?
小智 84
Spring Boot Reference中的第19.2节告诉您在启用远程调试支持的情况下启动应用程序.
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myproject-0.0.1-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
启动应用程序后,只需在运行/调试配置中添加远程Java应用程序配置,选择启动应用程序时定义的端口/地址,然后就可以自由调试.
Dur*_*ris 20
更简单的解决方案
而不是键入mvn spring-boot:run,只需键入mvnDebug spring-boot:run
您仍然需要通过在相关端口上为"远程Java应用程序"创建新的调试配置来在Eclipse中附加调试器.
Abd*_*ull 17
假设您已成功遵循Spring Boot的指南,将Spring Boot应用程序设置为服务.您的应用程序工件驻留在/srv/my-app/my-app.war配置文件中/srv/my-app/my-app.conf:
# This is file my-app.conf
# What can you do in this .conf file? The my-app.war is prepended with a SysV init.d script
# (yes, take a look into the war file with a text editor). As my-app.war is symlinked in the init.d directory, that init.d script
# gets executed. One of its step is actually `source`ing this .conf file. Therefore we can do anything in this .conf file that
# we can also do in a regular shell script.
JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=localhost:8002,server=y,suspend=n"
export SPRING_PROFILES_ACTIVE=staging
Run Code Online (Sandbox Code Playgroud)
当你重新启动Spring Boot应用程序时sudo service my-app restart,那么在它的日志文件中/var/log/my-app.log应该是一行说Listening for transport dt_socket at address: 8002.
打开到服务器的SSH端口转发隧道:ssh -L 8002:localhost:8002 myusername@staging.example.com.保持此SSH会话运行.
在Eclipse中,从工具栏中选择Run - > Debug Configurations - >选择Remote Java Application - >单击New按钮 - >选择Connection Type Standard(Socket Attach),Host localhost和Port 8002(或任何你拥有的)在之前的步骤中配置).单击Apply,然后单击Debug.
Eclipse调试器现在应该连接到远程服务器.切换到Debug透视图应该显示连接的JVM及其线程.断点应在远程触发后立即触发.
Arp*_*wal 13
运行以下命令pom.xml放置位置:
mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Run Code Online (Sandbox Code Playgroud)
并在端口上启动带有调试选项的远程Java应用程序5005
在我看来,最好的解决方案是在pom.xml中添加一个插件,你不需要一直做任何其他事情:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9898
</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
小智 5



| 归档时间: |
|
| 查看次数: |
156089 次 |
| 最近记录: |