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

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.

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

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”.

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.

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

Resources