Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start up spring-boot application via command line?

I have a spring-boot application which I need to start up by going to the folder directory and start up my web application via command line. I have a class called Application.java and the code inside it is as followed.

@SpringBootApplication(scanBasePackages = {"com.ubs.tas.topcat.dashboard"}) public class Application extends SpringBootServletInitializer {     private static final Logger LOGGER = LoggerFactory.getLogger(Application.class.getName());     private static final Class<Application> applicationClass = Application.class;      @Override     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {         return application.sources(applicationClass);     }      public static void main(String[] args) {         LOGGER.info("Starting...");         SpringApplication.run(Application.class, args);     } } 

I set up classpath then tried to run the command "java ApplicationUtility" but I'm getting this error message "Could not find the main class: ApplicationUtility. Program will exist."

like image 345
user4900074 Avatar asked Dec 15 '17 16:12

user4900074


People also ask

Can I run Spring Boot application from command line?

To run your Spring Boot app from a command line in a Terminal window, you can you the java -jar command. This is provided your Spring Boot app was packaged as an executable jar file.

How do I run a Spring Boot program in Mvn?

The Spring Boot Maven Plugin implement a custom ClassLoader to locate and load all the external jar libraries now nested inside the package. automatically find the main() method and configure it in the manifest, so we don't have to specify the main class in our java -jar command.

What is Spring Boot command line?

Spring Boot CLI(Command Line Interface) is a Spring Boot software to run and test Spring Boot applications from command prompt. When we run Spring Boot applications using CLI, then it internally uses Spring Boot Starter and Spring Boot AutoConfigurate components to resolve all dependencies and execute the application.


2 Answers

I presume you are trying to compile the application and run it without using an IDE. I also presume you have maven installed and correctly added maven to your environment variable.

To install and add maven to environment variable visit Install maven if you are under a proxy check out add proxy to maven

Navigate to the root of the project via command line and execute the command

mvn spring-boot:run 

The CLI will run your application on the configured port and you can access it just like you would if you start the app in an IDE.

Note: This will work only if you have maven added to your pom.xml

like image 112
Adindu Stevens Avatar answered Sep 21 '22 18:09

Adindu Stevens


You will need to build the jar file first. Here is the syntax to run the main class from a jar file.

java -jar path/to/your/jarfile.jar fully.qualified.package.Application  
like image 27
Srikanth Anusuri Avatar answered Sep 17 '22 18:09

Srikanth Anusuri