How to run Spring Boot web application in Eclipse itself?

246,612

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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.

Share:
246,612

Related videos on Youtube

Krishan Babbar
Author by

Krishan Babbar

Having in web development since 2004. Have worked on PHP, Core Java, Spring, Struts, Hibernate, JQuery, Javascript, CSS, HTML, Hazelcast, ZKoss (ZK) and many more.

Updated on June 17, 2021

Comments

  • Krishan Babbar
    Krishan Babbar about 3 years

    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?

  • Krishan Babbar
    Krishan Babbar about 10 years
    Thanks, I was able to run other applications' main method but for above said application i did not see option of "Run as Application".
  • geoand
    geoand about 10 years
    @KrishanBabbar When you right-click and can you not see Run as -> Java application?
  • Krishan Babbar
    Krishan Babbar about 10 years
    Nope, i could not see.
  • geoand
    geoand about 10 years
    @KrishanBabbar That is very weird, to Eclipse running a Spring Boot application should be transparent...
  • Mukun
    Mukun over 9 years
    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 ?
  • Darren Parker
    Darren Parker over 9 years
    Yes, stop and restart the server for it to reload updates to classes.
  • Mukun
    Mukun over 9 years
    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. github.com/spring-projects/spring-boot/issues/110 . Hope I understood correct
  • Oded Peer
    Oded Peer about 9 years
    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.
  • geoand
    geoand about 9 years
    @OdedPeer You mean the Maven/Gradle Spring Boot plugin?
  • Oded Peer
    Oded Peer about 9 years
    I am using Maven. when I run spring-boot:run my code is swapped (but the forked process needs to be killed explicitly)
  • geoand
    geoand about 9 years
    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
  • Prashanth Debbadwar
    Prashanth Debbadwar about 8 years
    This way if I run second time then I am getting java.net.BindException: Address already in use exception.. How to solve it?
  • Darren Parker
    Darren Parker about 8 years
    @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.
  • sanjay patel
    sanjay patel over 7 years
    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.
  • Shilan
    Shilan over 6 years
    I am running on STS now, but I don't know why for this specific project I have, the boot run has disappeared.
  • Paulo Merson
    Paulo Merson over 6 years
    @Shilan Do you see "<nature>org.springframework.ide.eclipse.core.springnature</‌​nature>" in your .project file? If not, try adding it.
  • Akshay Lokur
    Akshay Lokur over 6 years
    and how do I debug app in Eclipse?
  • Giuseppe Gallo
    Giuseppe Gallo almost 4 years
    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.