0

I have a Spring Boot JAR Application. When I run it, no browsers automatically show https://localhost:8080/. But typing manually the mentioned URL works fine, and the application runs.

@SpringBootApplication
@ImportResource({ "classpath:applicationContext.xml" })
public class StockMaintenanceSystemApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(StockMaintenanceSystemApplication.class, args);
    }

}

Do I need to set the URL(https://localhost:8080/) anywhere? If not, please correct my code.

Elyas Hadizadeh
  • 3,289
  • 8
  • 40
  • 54
Abhishek Rana
  • 107
  • 2
  • 14

4 Answers4

2

When you build the jar file and run it, it will not automatically open the browser for you. The file jar is used when deploying on the server environment, this is completely different from the developer environment you're still used to, where when you use the IDE, your job is to just click the "run button", the IDE will build the jar file, run it and automatically open the browser for you.

The solution for you here is you can write function that execute shell command like that and call it on main function. The shell command can be chrome.exe localhost:8080

Do Trung Duc
  • 396
  • 3
  • 13
1

If I understand correctly, you mean that the browser doesn't open a new tab when you start a spring boot application.

If that is the case, it shouldn't open a new tab, it simply starts a service on your pc, you need to navigate to the address manually. It is simply not something that spring boot does.

Daniel B.
  • 2,491
  • 2
  • 12
  • 23
0

Opening a browser after running your application is IDE's responsibility. IDEs can only open a browser when you package the application as a WAR file, configure an application server, like Tomcat, and restart the container via IDE.

So if you package the application as JAR file, it is necessary to open a web browser and type the desired link(localhost:8080). But there are some tricks to cope with this situation.

Elyas Hadizadeh
  • 3,289
  • 8
  • 40
  • 54
-2

I resolved my problem.

import java.io.IOException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource({ "classpath:applicationContext.xml" })
public class StockMaintenanceSystemApplication {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(StockMaintenanceSystemApplication.class, args);
        openHomePage();
    }

    private static void openHomePage() throws IOException {
        String url = "http://localhost:8080/";
        Runtime rt = Runtime.getRuntime();
        rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
    }
}
Abhishek Rana
  • 107
  • 2
  • 14