51

I am able to run few sample applications in my Eclipse (STS). Now, I want to run a web application within eclipse itself.

I tried with sample application "spring-boot-sample-web-jsp" given at the link and I am able to export its war into external tomcat and run the application. Now my question is how to run a Spring Boot Web application into eclipse itself?

Paolo
  • 20,112
  • 21
  • 72
  • 113
Krishan Babbar
  • 766
  • 1
  • 7
  • 17

11 Answers11

136

This answer is late, but I was having the same issue. I found something that works.
In eclipse Project Explorer, right click the project name -> select "Run As" -> "Maven Build..."
In the goals, enter spring-boot:run then click Run button.

I have the STS plug-in (i.e. SpringSource Tool Suite), so on some projects I will get a "Spring Boot App" option under Run As. But, it doesn't always show up for some reason. I use the above workaround for those.
Here is a reference that explains how to run Spring boot apps:
Spring boot tutorial

Conrad
  • 91
  • 2
  • 8
Darren Parker
  • 1,772
  • 1
  • 20
  • 21
  • So how reloading works ?. When I make changes in Controller or any other class it does not reload. do we need to run the app manually ? – Mukun Feb 27 '15 at 11:32
  • Yes, stop and restart the server for it to reload updates to classes. – Darren Parker Feb 27 '15 at 15:02
  • that is inconvenient to manually stop and start on every class code change. But I also noticed it is not required if your IDE supports hotswap changes to classes that don't affect method signature. https://github.com/spring-projects/spring-boot/issues/110 . Hope I understood correct – Mukun Mar 02 '15 at 03:38
  • This way if I run second time then I am getting java.net.BindException: Address already in use exception.. How to solve it? – Prashanth Debbadwar Jun 21 '16 at 12:42
  • @Prashanth Debbadwar I think you forgot to stop the first run before starting it a second time. For the 2nd attempt, the tomcat server could not start since port 8080 was still in use by the 1st run. Click the red 'Terminate' button before attempting to run a 2nd time. Hope that helps. – Darren Parker Jun 21 '16 at 13:53
  • spring-boot:run and eclipse running main class are somehow differnt for me. For me my project where I have used mongodb, if I run using spring-boot:run it accept connection to standalone mongodb, while eclipse run tries to spin up embeded mongo db. – sanjay patel Jan 05 '17 at 00:05
  • 1
    and how do I debug app in Eclipse? – Akshay Lokur Nov 28 '17 at 07:07
  • Look into [Spring Boot Developer Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools). Simply by adding a dependency you may get auto-loading to work when running in the IDE. – Garret Wilson Mar 17 '23 at 15:39
26

Just run the main method which is in the class SampleWebJspApplication. Spring Boot will take care of all the rest (starting the embedded tomcat which will host your sample application).

geoand
  • 60,071
  • 24
  • 172
  • 190
  • Thanks, I was able to run other applications' main method but for above said application i did not see option of "Run as Application". – Krishan Babbar May 15 '14 at 12:27
  • 1
    @KrishanBabbar When you right-click and can you not see `Run as -> Java application`? – geoand May 15 '14 at 12:29
  • Nope, i could not see. – Krishan Babbar May 15 '14 at 12:40
  • @KrishanBabbar That is very weird, to Eclipse running a Spring Boot application should be transparent... – geoand May 15 '14 at 12:42
  • 1
    When you run the Spring Boot plugin you get hot deploy of code. When you run your application as a Java process you lose this capability. – Oded Peer Jul 06 '15 at 06:52
  • @OdedPeer You mean the Maven/Gradle Spring Boot plugin? – geoand Jul 06 '15 at 07:05
  • I am using Maven. when I run spring-boot:run my code is swapped (but the forked process needs to be killed explicitly) – Oded Peer Jul 06 '15 at 07:22
  • I see. The good thing with the boot plugins is that you they have Spring Loaded configured for hot-swap, but in my opinion they make it harder to debug due to the need to setup remote-debugging in the IDE – geoand Jul 06 '15 at 07:47
24

Steps: 1. go to Run->Run configuration -> Maven Build -> New configuration
2. set base directory of you project ie.${workspace_loc:/shc-be-war}
3. set goal spring-boot:run
4. Run project from Run->New_Configuration

enter image description here

Md. Kamruzzaman
  • 1,895
  • 16
  • 26
  • how can I add paramters like -Dspring.profiles.active=svil? I tried to put it then tab JRE in VM Arguments but it doesn't work. – Giuseppe Gallo Jul 29 '20 at 14:49
9

First Method:(if STS is available in eclipse)
1.right click on project->run as ->Spring Boot app.

Second Method:
1.right click on project->run as ->run configuration
2. set base directory of you project ie.${workspace_loc:/first}
3. set goal spring-boot:run
4. Run

Third Method:
1.Right click on @SpringBootApplication annotation class ->Run as ->Java Application

8

Choose the project in eclipse - > Select run as -> Choose Java application. This displays a popup forcing you to select something, try searching your class having the main method in the search box. Once you find it, select it and hit ok. This will launch the spring boot application.

I do not have the spring tool suite installed in eclipse yet and still, it works. I hope this helps.

Kaushal Jha
  • 81
  • 1
  • 2
7

I was also trying to run Spring Boot application in Eclipse, without any plugins.

Step 1

Right click on your project. Select "Run As" -> "Maven build...". Then in "Goals" field, enter "spring-boot:run". Apply & Run.

After this you do not have to Run again.

Step 2

After making any change, clean your project. After cleaning, it automatically builds the project once. Then when you will refresh your pages on browser, change will be reflected.

rsp
  • 813
  • 2
  • 14
  • 26
6

You can also use the "Spring Boot App" run configuration. For that you'll need to install the Spring Tool Suite plug-in for Eclipse (STS).

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72
  • 1
    I am running on STS now, but I don't know why for this specific project I have, the boot run has disappeared. – Shilan Oct 10 '17 at 08:43
  • @Shilan Do you see "org.springframework.ide.eclipse.core.springnature" in your .project file? If not, try adding it. – Paulo Merson Oct 10 '17 at 11:17
1

In my case, I had to select the "src/main/java" and select the "Run As" menu Just like this, so that "Spring Boot App" would be displayed as here.

JefinOJ
  • 13
  • 6
0

If you are doing code in STS you just need to add the devtools dependency in your maven file. After that it will run itself whenever you will do some change.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>
0

May be useful for someone.. In Run as if you are getting only java application (No spring bootapp).. then probably you need to install "Spring Tools (aka Spring IDE and Spring Tool Suite)" through Eclipse market place. After successful installation and restart of Eclipse.. now you can see in Run as "Spring Boot app".

Suraj
  • 11
  • 3
0

For me i wasn't seeing the option because spring tool suite was not correctly installed in my eclipse. I used this solution : Missing Spring Properties Yaml Editor and and Spring Properties Editor with Spring Tools 3.9.2

note that my eclipse wasn't able to install it because of dependence conflict i had got to unistall all spring plugin and install again

after install the option showed up

Sen'IT
  • 66
  • 2
  • 4