Home > Java > javaTutorial > body text

How to package springboot project into jar package

WBOY
Release: 2023-05-24 15:25:23
forward
13611 people have browsed it

    1. Why packaging

    After the project is developed, the front-end and back-end applications will be packaged and then deployed to the server for running. Before using Spring Boot, Java web applications are generally packaged into war packages and then combined with Tomcat to complete deployment. For Spring Boot, the official recommendation is to package the Spring Boot application into a fat jar (the default packaging method of Spring Boot), that is, the project's dependent jar package will also be included in the jar package of the Spring Boot project. This fat jar will build Tomcat Come in, so there is no need to configure Tomcat separately when deploying. Just upload the jar package without pre-installing any server, and deploying SpringBoot applications becomes very simple.

    2. How to package

    (1) Use IDEA for packaging

    1. Open the project, right-click the project and select Open Module SettingsEnterproject Structure, as shown below:

    How to package springboot project into jar package

    ##Select

    Artifacts and click the plus sign in the middle (Project Settings->Artifacts-&gt ;JAR->From modules with dependencies), as shown in the figure below:

    How to package springboot project into jar package

    2. Pop up

    Create JAR from Modules and select ‘Main Class&rsquo ;, and then click OK

    How to package springboot project into jar package

    3. Start packaging, click Maven Projects on the right, open

    LIfecycle, first click clean , and then click package to generate the target folder, which contains the jar file named after the project name and version number, and the packaging is completed.

    How to package springboot project into jar package

    (2) Use maven for packaging

    SpringBoot comes with a simpler spring-boot-maven-plugin plug-in that can be used for packaging, just Add the following configuration to pom.xml:

    <project>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>
    Copy after login

    No configuration is required. This plug-in will automatically locate the entry Class of the application. Execute the following Maven command to package:

    $ mvn clean package
    Copy after login

    3. Run jar Package

    Enter the folder where the jar is located, use the

    java -jar command to run the jar, and the project will start

    java -jar demoa-0.0.1-SNAPSHOT.jar
    Copy after login

    How to package springboot project into jar package

    4. Note

    Because springboot has built-in tomcat, packaging the springboot project into a jar can eliminate the need for tomcat configuration. If it is packaged into a war package, you also need to configure tomcat.

    After packaging, there are two jar files in the target directory. One of the jar packages has the suffix

    .original. This is the jar package created by the Maven standard packaging plug-in. It only contains our own The Class does not contain dependencies, and the suffix .jar is the jar containing dependencies created by the SpringBoot packaging plug-in, which can be run directly.

    The above is the detailed content of How to package springboot project into jar package. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!