Spring-Boot 2.2.0 process fails to terminate when launched in debug mode - spring-boot

When running spring-boot 2.2.0 in debug mode in both Eclipse 2019-06 and IntelliJ 2019.2, attempts to terminate the process via the IDE look like they kill the process (per the IDE), however, the java process is still running (verified by ps -ef | grep java).
When running non debug mode in Eclipse, the process can be terminated but Eclipse displays a message stating "terminate failed".
I've tried all sorts of older post options including:
-Dspring-boot:run.fork=false
-Dfork=false
Running spring at cmd line using mvn spring-boot:run terminates normally with ctrl-c.
I'm not using any spring plugins in Eclipse. I'm using open jdk 11.0.3+7.
Everything worked normally in spring-boot 2.1.7, 2.1.8 and 2.1.9
Is this possibly a bug in spring-boot 2.2.0?

With Spring Boot v2.2.0.RELEASE, JVM process forking is enabled by default when starting from the maven plugin:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes#fork-enabled-by-default-in-maven-plugin
At this time, Intellij's maven plugin in 2019.2 and earlier versions don't appear to associate the child process to the debugging session and the IDE is even unable to shutdown the process once started.
None of the solutions in the references below worked for me. The only way I found to disable forking was to set the flag directly in the spring-boot-maven-plugin in the pom.xml like so:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- disable process forking that is enabled by default in spring-boot 2.2.0.RELEASE and higher -->
<fork>false</fork>
</configuration>
</plugin>
Afterward, I can now right-click on spring-boot:run, select debug, and the debugger connects to the right child process.
Additional references:
https://github.com/spring-projects/spring-boot/issues/18638
https://github.com/spring-projects/spring-boot/issues/18706

I had the same problem when I moved to 2.2.0 (+ JDK 11).
As #guidadic said : since 2.2.0, the JVM is forked by default.
Unfortunately for me, if I disable forking, I lose some features, like colour in the console, which worked before with no fork. In addition, forking allows to use DevTools, with live reloading, which is pretty interesting.
After a long and hazardous search on Internet, I found out a solution on a non related Stackoverflow answer somewhere (I lost the link).
In your main method, get your application context from the run method, and then open a console scanner.
When you will press the red square to kill your app in Eclipse, the scanner throws an exception : the Eclipse managed (visible) thread is the one linked to the console, so the scanner doesn't like that you dare to stop it.
You just need to catch it to exit from the application :
log.info("Press 'Enter' to terminate");
try (Scanner scanner = new Scanner(System.in)) {
scanner.nextLine();
}
finally {
log.info("Exiting");
System.exit(SpringApplication.exit(context));
}
Additionally, if you press 'enter' in your Eclipse console, it will exit your application and terminate all the application JVMs.

Related

Intellij cannot debug cucumber + serenity test run

I got java cucumber + serenity project in Intellij
I configured the maven run configure:
Working directory: xxxxx
Command line: clean verify "xxxxx"
The run configure works fine before, I can use it run test as well as fire up the debug mode.
However, one of sudden, I cannot run the debug mode anymore. Even though I clicked the debugged button (green little bug) it never stops at the break point.
It still stops if I added break point to java.lang Object class, but it never stops at any break point from actual test methods, very weird...any one can help? Thanks
Surefire starts a new jvm to run tests (a fork). You are debugging the jvm that starts the second jvm, not the jvm that runs the tests.
Either change the fork mode or attach a debugger to the forked jvm.
http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html

Cannot debug / stop a springboot app with IntelliJ Idea community

My Idea setup cannot stop on breakpoints and not even stop the launched/debugged process.
Environment:
ubuntu 20.04.1 LTS
openjdk version "1.8.0_275" 64 bit
IntelliJ Idea 2020.2
Steps to reproduce:
Create a maven "demo" application from https://start.spring.io/ (Spring Web dependency will suffice)
Download IntelliJ Idea and launch idea.sh
Open pom.xml file to import the project in the IDE
Add a #RestController returning "Hello world" for #GetMapping("/")
Drop a couple of breakpoints in the App and in the newly created controller
Configure a maven launcher with spring-boot:run command line
Hit the debug button
The application launches and you can call http://localhost to see the "Hello world"; you can even change the code and the app nicely reloads but ... it does not stop on breakpoints.
When you hit the stop button the IDE detaches from the process but does not stop it.
What's wrong with my setup?
BTW: debugging works smoothly for a simple cli maven java application.
Thanks to the suggestion from https://stackoverflow.com/a/47064387/509565 I've worked out the solution:
Use spring-boot:run -Dspring-boot.run.fork=false as your laucher command line
Ensure that "Delegate IDE build/run actions to Maven" in "Build ...> Build Tools > Maven > Runner" settings is NOT checked

How to debug start of eclipse plugin?

I try to migrate an eclipse plugin from Java8 to Java9. If I start a debug session (Run as Eclipse Application...) all works fine.
However, after installing my plugin I am not able to use it. If I use ss in the OSGI console I get following status for my plugin:
1102 STARTING org.treez.core_1.0.0.201712191435
and if I manually try to start it I get
osgi> start 1102
gogo: BundleException: Error loading bundle activator.
I tried to start a remote debug session, as suggested here:
Debugging Eclipse plug-ins
I set a break point in the constructor of my Activator but that break point is never reached.
=> How can I get additional information about why the loading of the bundle activator fails? Is there some log file? Can I somewhere set a logging level to TRACE?
I assume that the issue might be that a resource can be found while debugging the Eclipse Application but not when using the bundled jar. More info, e.g. the name of the resource that could not be found, would be very helpful.
Related questions:
Debugging Eclipse plug-ins
CQ5 OSGi bundle does not start:- Activator cannot be found
When plugins fail to start there is normally a message in the .log file in the workspace .metadata directory.
On Linux, Unix and macOS this file and directory are hidden so you may need to do something special to see them.

How can I debug with the Cloud-SDK-based Maven App Engine plugin?

I'd like to debug with the Cloud-SDK Based Maven plugin (com.google.cloud.tools::appengine-maven-plugin v. 1.3.0).
I run the goal appengine:run in Eclipse in Debug, but this does not put me into Debug mode, e.g. stopping on breakpoints.
I can use remote-debugger, but it is a hassle to run two processes every time I need to start my application. Is there a way of running a Debug session with one command?
I believe the only way to do this with Maven is by setting up a remote debug configuration in Eclipse as described in the App Engine documentation.
<configuration>
<jvmFlags>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</jvmFlag>
</jvmFlag>
</configuration>
Your eclipse remote debug configuration needs to use the port specified in the jvmFlag arguments.
Another more practical way to run the debugger is to use Google Cloud Tools for Eclipse.

Can the IntelliJ IDEA run tab have color?

I am running a spring boot application inside IntelliJ IDEA and noticed a difference if I run it via the run tab (run menu) and via manual command from the terminal tab.
If I run it through a maven run target (play button), I do not see any colors inside the 'run' tab. If I run it via 'mvn spring-boot:run from the 'terminal' tab I see the pretty color highlights. The maven run configuration also runs the same command, spring-boot:run.
Application started from the play button/run configuration (run tab):
Application started from the terminal tab via mvn spring-boot:run (terminal tab):
Inside build.gradle, add the following block to get colorized log output when running your Spring Boot app inside IntelliJ IDEA via gradle bootRun.
bootRun {
jvmArgs = ["-Dspring.output.ansi.enabled=ALWAYS"]
}
It's supported for the Spring Boot Run/Debug configuration type. It explicitly passes
-Dspring.output.ansi.enabled=always
JVM option enabling the color output.
As far as I know, ANSI colors support is not available when you run it in IntelliJ IDEA using Maven or Gradle configurations in the built-in console. Feature request is welcome.
In IDEA 2017.1 EAP I'm getting colours even if I'm just running the application with the standard run command
Edit:
Might be that Community edition doesn't support Spring Boot at all (https://www.jetbrains.com/idea/features/editions_comparison_matrix.html)
You can obtain the very same output also in the Community Edition with the previously mentioned option:
-Dspring.output.ansi.enabled=always
Simply go to "Run" -> "Edit Configurations..." and add the option in the "VM options:" field for your main class.

Resources