Cannot debug / stop a springboot app with IntelliJ Idea community - spring-boot

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

Related

How to create Kotlin console application that would actually open in a console window

I'm trying to create a Kotlin console app using IntelliJ Idea.
For some reason it doesn't run as a console app.
I'm using IntelliJ IDEA 2020.3.1 (Community Edition) on Windows 10.
What I do is as follows - I create a new Kotlin project out of the "Console Application" template. I choose openjdk-15 as the Project JDK:
It generates a project consisting of a simple "Hello world" function:
fun main(args: Array<String>) {
println("Hello World!")
}
When run it, it simply terminates (as expected) - without opening any console window though:
If I add some code that would require interaction from the user:
fun main(args: Array<String>) {
val name = readLine()
println("Hello $name!")
}
Once try to execute it, it builds but then hangs, never completing. Apparently it waits for the user input that's never submitted.
This is understandable, but underlines the problem - so where's the console??
I tried to fiddle with "Edit Configurations"
Do I possibly need a different JDK?
What is the solution if I simply want to build a regular console application running in text mode? (Like one I could trivially create using Visual Studio.)
You ran it with Gradle so you don't actually get an interactive console (just the text output of Gradle).
Go to settings and under Build, Execution, Deployment -> Build Tools -> Gradle set Build and run using: to IntelliJ.
When you run your program IntelliJ (and not Gradle) complies and runs it and you can actually see an interactive console window (inside IntelliJ).
If you wan't to build/ship the app you'll have to build it with Gradle (I recommend the Shadow Plugin to make a single jar file out of it) and run the .jar file inside a console (java -jar myApp.jar).

Gradle / IntelliJ miscommunication causing "Unable to start daemon process"

My IntelliJ Idea projects have been working fine until I cloned a new project from our repo and installed Gradle.
This new project runs, but running the debugger causes the following error:
I've completed the steps recommended in this similar SO question. I have also read the Gradle Daemon guide.
Some helpful information:
-Gradle does respond to command line prompts, including --profile and --status:
-The project builds and executes; the problem is only the debugger. Is this a mapping issue between IntelliJ and Gradle?
-In the Settings menu, Gradle JVM: is set to "Use Project JDK (Java version "1.8.0_211") and this program is written in Java 8. Delegate settings set to: Build and run using intelliJ IDEA. Run tests using IntelliJ IDEA. Should these change to Gradle?
-I took the advice of one of the respondents and had one of our IT guys check out my ports and firewall settings. He was unable to solve the problem and said the issue is with Gradle.
So far, nothing has worked. What should I do?
I solved this problem after some tinkering:
In (IntelliJ) File > Settings > Build, Execution, Deployment > Gradle, I changed "Use gradle 'wrapper' task configuration" to "Use local gradle distribution."
Also, notice in this screenshot that "Gradle VM options" has a custom value; this was suggested as a solution in another post. This relates to memory management, as some people speculated that the daemon was crashing because of a RAM issue. My solution appears to work regardless of whether I alter that value.

import source code (meant for eclipse spring STS) into intellij

How to import and run spring mvc github source code meant for Eclipse Spring STS into IntelliJ?
What I did:
downloaded working spring mvc project source code zip file https://github.com/simplyi/springmvc-ws?fbclid=IwAR2xKg6Oh0YHLuVJ2YEh2vt6cr1u3-4E4IzKnPMDJVc6nvI-BN6pRaPMKHQ
'import' upon starting Intellij
don't know what configurations to pick so got a lot of errors. SO, followed this https://www.lagomframework.com/documentation/1.5.x/java/IntellijMaven.html?fbclid=IwAR3JaAw6dF2jX9k4fxxKg37j8mpNI2dNTEqupVULzLrk83G_wEtN4beNJsI
BUT got error:
ERROR] No plugin found for prefix 'lagom' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories
So, I'm giving up on this tutorial in above link.
Here is gyazo screenshot of Intellij terminal errors:
https://gyazo.com/7f83cca2baeff6ca383885f814325477
This gyazo screenshot shows external libraries:
https://gyazo.com/6e2898508b64061ebf726fc46881b0ef
How to import this source code into Intellij & run/test the webapp?
Thank you!
The project you linked to looks like a standard maven Spring Boot application.
Download and unzip the project
Start IntelliJ
At the Welcome screen, select "Open" (instead of import)
Navigate to the project folder/directory and click "Open"
That's it! IntelliJ will detect the maven structure and will setup the project appropriately (downloading dependencies, etc., which might take a couple of minutes).
To start the application, you can click on the "maven" panel on the right side of the screen, find the spring-boot plugin, and select spring-boot:run.
ps. it looks like this particular project was written for JDK 8. If you're using JDK 9 or above then you may need to make changes to make the project run.
I've downloaded and run the Spring Boot application from your link.
It starts and passes the tests.
Short answer
Looks that your problem is what class you're running.
Run \springmvc-ws\src\test\java\com\appsdeveloperblog\app package as JUnit to run the tests.
Run com.appsdeveloperblog.app.ws.MobileAppWsApplication class as Spring Boot application to run the application.
Long answer
What I've done to run the application and the tests:
Clone the project from github: run git clone https://github.com/simplyi/springmvc-ws.git in the console.
The project will be cloned into springmvc-ws sub-directory of from where you executed git clone.
In IDEA, select File -> Open (from keyboard: Alt + F, O), select the cloned springmvc-ws folder.
Select OK. If required, answer to open it in current or new window.
Wait for the project to be imported (no running operations displayed in the bottom status bar).
To run the application
Open class MobileAppWsApplication (you can type it in Ctrl + N as a quick "Go to class" shortcut).
Press Shift + Alt + F10.
Select execution with Spring Boot icon and select Run. See the screenshot below.
In Run tool window at the bottom, you'll see that the application has started on localhost:8080 under the context-path /mobile-app-ws:
2019-06-21 15:42:51.585 INFO 31920 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/mobile-app-ws'
2019-06-21 15:42:51.588 INFO 31920 --- [ main] c.a.app.ws.MobileAppWsApplication : Started MobileAppWsApplication in 8.688 seconds (JVM running for 10.143)
In the Endpoints tab of this Run tool window, you can see the web-service endpoints of the started application.
To run the tests
Stop the application if it is running (Red Stop button in Run tool window), to not have the clashing ports.
In Project window (Alt + 1), select the directory \springmvc-ws\src\test\java\com\appsdeveloperblog and press Shift + Alt + F10 on it.
Select the point with JUnit (arrows) icon on it and then select Run point. See the screenshot below.
Run tool window will activate. Wait for the tests to pass. You can expand the directory to see the tests results.

Maven Selenium project Execution Not visible with Jenkins build Now

I am using selenium maven project with Jenkins and when I run build now, execution is running in background for which I am able to see output in consol but my browser and all execution on browser is NOT visible.
I tried searching around and change Jenkins service by checking allow window interaction checkbox but still not able to view it. I m running on window 10 and running with local(http://localhost:8080). I tried with Chrome, firefox & IE and all have same behavior of Not visible.
I used command "mvn clean test" in Build - Execute Windows batch command.
Same project is running with Eclipse & CMD very well with visible execution.
I am using Jenkins version 2.46.3.
Anyone experienced this? Any idea ?
Run Jenkins or slave from command line using war or jar provided, other option to try: check 'Allow service to interact with desktop' in Services.
After lots of search & troubleshoot, I found solution as I installed Jenkins as Window version (.exe) so I uninstalled it and downloaded Jenkins from official jenkins website(https://jenkins.io/download/) by clicking on Generic Java Package(.war) and then went into Command prompt and went to path where my Jenkins.war file dowloaded and install using java -jar jenkins.war and reregister with different accountname and password (created new account so it won't pull up the old account) and the Execution started DISPLAYING ON BROWSER. Hope this helps.

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