This is just a three step simple procedure to package your application into war.
Extending Main Class
First, we extend our main class to SpringBootServletInitializer. This tells spring that your main class will be the entry point to initialize your project in server.1234567@SpringBootApplication
public
class
Application
extends
SpringBootServletInitializer{
public
static
void
main(String[] args) {
SpringApplication.run(Application.
class
, args);
}
}
Overriding configure method
Next, we overload the configure method of SpringBootServletInitializer. We tell spring to build the sources from our Main class. Your final Main class should look like this:123456789101112@SpringBootApplication
public
class
Application
extends
SpringBootServletInitializer{
public
static
void
main(String[] args) {
SpringApplication.run(Application.
class
, args);
}
@Override
protected
SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return
builder.sources(Application.
class
);
}
}
Configure Packaging to WAR
Finally, we tell maven to package the project into WAR. In your pom.xml, change the attribute value for packaging from jar to warThen try to build your project using:1<
packaging
>war</
packaging
>
For Gradle Project, please see this Packaging executable jar and war files in the Gradle link to configure .gradle file to build war file.1mvn package
Comments
Post a Comment