Intellij Spring Boot project run configuration - spring-boot

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.

Related

UNABLE TO CREATE A NEW SPRING STARTER PROJECT

I'm not able to create a spring starter project in sts tool(spring tool suite).
While trying to create a new spring starter project then I have received the "Artifact transfer exception" error.
And also I have attached the screen shot for the same.
Can you help on this.
Try spring initializer (https://start.spring.io/), just substitute your values, then click generate, unarchive project and open, and all must works.
Acoording to the link that Stephen C said in his comment:
m2eclipse issues ArtifactTransferException - But pom.xml compiles / installs from the command line
Open folder by running this text (without Quotes) in Search Explorer of Window “%USERPROFILE%.m2″.
After running above command, “m2″ folder of maven will open. Now search for file (without Quotes) “*.lastUpdated”.
In this step, delete all the files found by running Step 2.
Now go to Eclipse project and select “Maven | Update Dependency” or “Maven | Update Project”.

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.

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

Jenkins plugin shows on Plugin page but does not show on configuration page

I am creating a hello world plugin for Jenkins by following Tutorial: Create a Jenkins Plugin to integrate Jenkins and Nexus Repository. After I followed the steps, I can run Jenkins and test the plugin.
It shows on Installed Plugin Page.
Then I go to Configuration page and expect to see Hello World Builder section like the below image, but there is not.
What steps did I miss? Is there anything I have to do before having that plugin show up on the configuration page?
Update
This is the project layout, I haven't modified anything on it yet.
What command did you use to generate the plugin skeleton?
FYI, from the tutorial above, mvn -cpu is deprecated.
To generate the plugin skeleton, use:
mvn hpi:create
or
mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create from the Jenkins Plugin tutorial
I'm going to include each step for what worked for me:
mvn hpi:create, then enter groupId (press enter to use default: org.jenkins-ci.plugins) and artifactId (name of the plugin)
cd new-plugin-name
mvn eclipse:eclipse
mvn package
mvn hpi:run
(default port is 8080, but you can set your own with Dport option (i.e. mvn hpi:run -Dport=9999, use this if port 8080 is in use - otherwise mvn hpi:run will fail)
Open browser and enter URL "localhost:8080" (or 9999)
You should the page below. Click the link and that'll take you to Jenkins home page
Click 'Manage Jenkins' > Configure System. Scroll down near the bottom of the page and you should see the Hello World Builder section
Go back to Jenkins home page and click New Item
Give the project any name, select Freestyle Project, click OK.
Scroll down to the Build section and click 'Add build step' > Say hello world
Enter a name (i.e. TestName), save the project, then run a build ('Build Now')
Click on the latest build under 'Build History' > Console Output.
I had a same problem and solved it.
I am sure you are using eclipse as IDE and imported HelloWorldBuilder as a maven project.
In my case, I converted it to eclipse project after deleted and regenerated again.
Please refer "Setting up a productive environment with you IDE" section of the following url and use this command.
mvn -DdownloadSources=true -DdownloadJavadocs=true -DoutputDirectory=target/eclipse-classes -Declipse.workspace=/path/to/workspace eclipse:eclipse eclipse:add-maven-repo
https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial
If you launch the project after convert and rebuild it, the hello world builder section will be shown in your jenkins configuration menu.
I recently had the same problem. Apparently currently (see date of this message) master of the hello world example is wrong. I needed to change
<artifactId>hello-world</artifactId>
to
<artifactId>hello_world</artifactId>
because some component in the middle doesn't accept "-". I think hpi:create will tell you that, unfortunately the debug log files don't. But the existing hello-world should already have those things correct.
Even I faced same problem, I think reason is because I imported to eclipse as a maven project. I deleted folder and ran command
mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
to create new project. Then ran mvn hpi:run and it showed up well.

applying mvn commands via intelliJ IDEA

How to run following mvn commands via intelliJ IDEA? I can run these commands from terminal but how to do the same in the IDE for the project opened in it?
--mvn clean dbmaintain:updateDatabase
--mvn clean package
Go to "Edit Configuration" and create a new "Maven Run/Debug Configuration". There you can define the command line and the working directory.
An other way of doing the same is : open de maven projects view (on right edge of the window) expend your module, expand the "Life-cycle", select the phase you need to run. Then a simple rigth click shows a popup allowing you to "run" the phase or create a run configuration preconfigured with the working dir and the phase. (you can always edit it)

Resources