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.
"
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With