Can the IntelliJ IDEA run tab have color? - spring

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.

Related

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

Intellij Spring Boot project run configuration

I run my Spring Boot project from the command line using mvn install and then mvn spring-boot:run -Dspring.profiles.active="development". This works fine but is not very convenient. I would like to start it directly from Intellij by clicking the green run button.
I tried to add a new run configuration but without success. I set "main class" and "active profiles" and tried to add "run maven goal" but the last one does not work (when I choose the working directory - the one with pom.xml - it says Maven projects not found). What should I exactly set up ? I just want to run the two commands mentioned above from the root directory of the project.
Update: here is the project structure project structure
Please follow the following steps:
Set the maven goal by clicking the "+" in IntelliJ (circled area)
Write mvn install.
Set the VM Options as: -Dspring.profiles.active=development
After that it should just run fine just by clicking the green play button.
This should help you get started.

how to set spring active profile environment variable in IntelliJ

I am using spring boot application (maven project) in eclipse. When I run test clean target of maven project, I want to load the active profiles
I have added the property spring.profiles.active=test,aop in application.properties and also in application-test.properties, this does not have any affect.
or setting this property in command line option of IntelliJ IDE as -Dspring.profiles.active=test,aop does not have an effect when the command is test clean. I have also tried setting the JVM argument of the Runner in Intelligent
however #ActiveProfiles("test") works when the test case class is executed from IntelliJ IDE( right click -> run TestCaseClass).
Any clues ?
Setting the VM Options with -Dspring.profiles.active=test
My Project is using MAVEN.
the easy was is
Right hand side click on MAVEN -> Expand the Profiles -> Click on desired profile.
Build and run
Please check the attached screenshot for more clarity

AEM6 starting from console with -debug -nofork options

As I know when AEM is started in debug mode from the console using the -debug option, the JVM will be forced to fork, but what will be the result if the AEM is started with the -debug -nofork options? e.g:
java -jar aem6-author-p4502.jar -debug 8000 -nofork
Fork or nofork does not matter. aem6 will decide based on the available memory. if you want to debug, using following command
java.exe -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9669,suspend=n -XX:+PrintGC -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -jar aem-quickstart-6.2.1.jar
then in intellj or eclipse connect it with remote debug. you can only debug the code in osgi bundles. you can't debug the jsp code.
What works for me is to double-click the server instance in Eclipse. It opens up the details. Near the right bottom corner, there is an option for "Debug". Expand it and uncheck the "Resolve sources when connecting".
This stops Eclipse from comparing your Eclipse code with the code running inside the server. This isn't an ideal answer. Ideally, we want to sync the Eclipse code with the server code, otherwise debugging has no meaning -- assume you're off by even one line of code when debugging.
I'm answering your specific question. For a broader answer on this, please see:
Eclipse java debugging: source not found
Sometimes our system OS generates multiple java forks in that case -nofork added at the end of the command will resolve the issue.

How to set system properties in IntelliJ IDEA 13 gradle task?

I have a Spring Boot project with gradle build tool. The JDBC url, username and password are kept in a property file which is not part of application it's a external property file, the path of the property file is taken from system properties as follows.
export _JAVA_OPTIONS=-DdatabaseConfiguration=db.properties
It is working if I run the application from terminal using gradle bootRun, but when I try to run from Intellij IDEA 13 gradle tasks its not working, the property value is null.
I tried the VM options in Run/Debug Configuration as in the below screen shoot its not working either
How can the JAVA_OPTIONS can be set in Intellij IDEA 13 gradle tasks.
This is because every time you use the Gradle tool window to kick off tasks in IntelliJ, it creates/overwrites the launch configuration for that task.
Basically, I've had to run from the Gradle tool window just once. Then I go into the failed Launch Config (shown in question) and enter the system property in the VM options. From there on out, I need to use that Launch Config to execute the task instead of the Gradle tool window.
Update: Even better solution:
Preferences->Build, Execution, Deployment->Build Tools->Gradle->Gradle VM options
Add your system properties there (i.e. -Dappengine.sdk.root=/opt/google/google-cloud-sdk/platform/appengine-java-sdk)
Doing this will keep them from getting overwritten/lost in the Launch configs that the Gradle tool window generates.
Another thing to note is that using the Gradle tool window causes the commands to be run without access to Environment Variables. This can cause a lot of problems with builds that depend on these env vars.
I ran into this today with the appengine-gradle-plugin and had to put
-Dappengine.sdk.root=/opt/google/google-cloud-sdk/platform/appengine-java-sdk
in the VM options because it was not seeing the env vars. From the command line, it picks up the env vars and works fine. This worked for my appengineRun task.
But it does not work for appengineUpdate since that gives another error caused by lack of env vars: Toolkit not found: apple.awt.CToolkit

Resources