Spring Boot war or jar for rest api project

spring boot jar to war
spring boot jar vs war
spring boot executable jar
spring boot without embedded tomcat
spring boot restful web services json example
spring boot jar vs war performance
war vs jar
how to run spring boot application in eclipse with tomcat

I want to develop sample REST API project using Spring Boot. I am confused what should be the proper approach as we have multiple options for packaging like war, jar etc.

I have requirement where I have external library folder which have multiple jar and resource files which will be used in REST API and front end (using React).

I want to keep jars and resource as external dependencies due to their dynamic changes and I do not want to include them in project. I have tried sample project using loader.path using jar which works fine but same approach doesn't working with war file. I am using Maven as build tool.

  1. What should be approach to achieve this in Spring Boot?
  2. Need working example in 2.xx version
  3. What should be used war or jar?
  4. How to configure IDE (Eclipse / IntelliJ) to use external lib folder with Spring Boot - I couldn't find solution for this.

Deploying Spring Boot app as WAR, WAR vs JAR. By default, Spring Boot applications are packaged as executable JAR files with embedded Tomcat. You can run them directly by  I want to develop sample rest api project using Spring-Boot. I am confused what should be the proper approach. As we have multiple option for packaging like war, jar etc., I have requirement where I have external library folder which have multiple jar files and resource file which will be used in rest api and front end (using react).

You should make it an executable Spring Boot JAR.

You only need a WAR if you have to deploy it on a Java EE server.

It's good that you're using Maven. Have it manage your dependencies and build the package.

You want to find the Maven plug-in that creates the executable JAR with dependencies included inside.

Update:

Here are my responses to your four questions:

  1. Don't mix and match Maven and /lib. Better to use mvn install to place all those external libraries you claim to need in your local .m2 or Maven repository.
  2. See Spring Boot guides for working examples. Perhaps the service and the React front end should be separate packages and deployments.
  3. This is Spring Boot, not Java EE. Use an executable JAR, not a WAR.
  4. See suggestion 1. Install those JARs in Maven. Do not mix and match.

I'd recommend that you consider deploying the REST service separately and let the React front end call it. De-couple the two. Let the REST service be a microservice that stands on its own, without a UI.

Tutorial: Use Spring Boot to Build and Deploy WAR Files, Building a Spring Boot application produces a runnable jar file by we included three dependencies for our project – one for REST, one for  Previously, the application contained a public static void main() method which the spring-boot-gradle-plugin was configured to run when using the java -jar command. By converting this into a WAR file with no XML files, you need a different signal to the servlet container on how to launch the application.

You could create an executable JAR file with dependencies using Apache Maven Assembly Plugin.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>${mainClass}</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Adding it to your pom.xml within <build></build> elements allows you to build both jar and jar-with-dependencies packages.

To build package use mvn clean package command.

Deploy a Spring Boot WAR into a Tomcat Server, Learn how to configure a Spring Boot application to be deployed on a Tomcat server. us to set up a production-ready setup of a Spring project, and Tomcat is one of the We add a simple REST EndPoint to return some valid content for us: First, we need to package a WAR application instead of a JAR. Building a Spring Boot application produces a runnable jar file by default. If your app includes server functionality, then Tomcat will be bundled with it. We need to ensure the Tomcat libraries don’t clash with an existing container (since the container will include the same libraries).

  1. If you need a standalone app go for a jar.
  2. If you need to deploy in server go for war.

Getting Started, It also shows values of com.example and rest-service as the Group and Artifact, respectively. <description>Demo project for Spring Boot</description> <​properties> You can also build a single executable JAR file that contains all the You can also build a classic WAR file. Creating API Documentation with Restdocs. Spring Boot WAR deployment example Created on: December 27, 2016 | Last updated on: September 30, 2017 websystiqueadmin Being able to start the application as standalone jar is great, but sometimes it might not be possible to run an app as jar [environment restrictions, company-wide regulations etc] and you have to build a WAR to be deployed

Getting Started, Spring Boot Actuator is a sub-project of Spring Boot. This guide takes you through creating a “Hello, world” RESTful web service with gradlew clean build && java -jar build/libs/gs-actuator-service-0.1.0.jar First, you need to give some thought to what your API will look like. JAR. You can also build a classic WAR file. Converting a Spring Boot JAR Application to a WAR. Spring Boot comes with two powerful plugins: They both essentially have feature parity and provide the ability to run Spring Boot apps from the command line as well as bundle up runnable JARs. This subject is mentioned in almost every guide at the execution phase towards the end.

Getting Started, Essentially, you have to reconfigure your project to produce a WAR file and declare the embedded container dependencies as "provided". This ensures that the  Introduction. Spring Boot is a convention over configuration framework that allows us to set up a production-ready setup of a Spring project, and Tomcat is one of the most popular Java Servlet Containers. By default, Spring Boot builds a standalone Java application that can run as a desktop application or be configured as a system service,

Spring Boot war Packaging Example, In Spring boot applications, default packaging is jar which is deployed in embedded servers. If you want to generate a war file for deployment in seperate  Note In Spring Boot, the new final executable JAR file with embedded server solution may not suitable in all production environments, especially the deployment team (a team with good knowledge of server optimization and monitoring skills, but lack of, the development experience), they want full control of the server, and they don’t touch code, so, we need a traditional WAR file.

Comments
  • Thanks Shubham for your answer, this seems to be working for me
  • Thanks for your answer, I will try link for working example and update you
  • I have tried your sample code but it creates jar with dependencies and I am not looking for this, I want to create Spring-Boot jar without dependency and all the dependency should be copied in lib folder. I found option in maven which allow to create jar without dependency and copies all the required jar in lib folder