I am trying to run a SpringBoot application from a JAR file, which I have built using VSCode's Project Manager from Java.
The app runs smoothly when running from VSCode, or when running from the command line, using
mvn spring-boot:run
This is my Main Class file:
package com.jvc.interconnectingflights.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.jvc.interconnectingflights")
public class InterconnectingFlightsApplication {
public static void main(String[] args) {
SpringApplication.run(InterconnectingFlightsApplication.class, args);
}
}
This is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jvc</groupId>
<artifactId>interconnecting-flights</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>interconnecting-flights</name>
<description>SpringBoot app</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is the output I am getting when running from the JAR:
22:05:28.287 [main] INFO com.jvc.interconnectingflights.app.InterconnectingFlightsApplication - Started InterconnectingFlightsApplication in 3.102 seconds (process running for 3.46)
22:05:28.318 [SpringApplicationShutdownHook] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@78e94dcf, started on Tue Jan 31 22:05:25 CET 2023
I have tried all the answers from related posts, but still no luck. I would really appreciate any advice!
Tried answers from this post and related ones:
Created a new JAR using mvn package
, which turned out to work. VSCode's Java Project Manager doesn't seem to build the JAR correctly