maven 项目 打包发布

3,009 阅读1分钟

1.pom.xml顶部添加<packaging>jar</packaging>

    <groupId>com.springboot</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>demo</name>

2.pom.xml底部添加<mainClass>com.springboot.demo.DemoApplication</mainClass>,避免找不到主类

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.springboot.demo.DemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

3.在pom.xml所在目录通过终端执行 mvn clean package

4.一般打包好的jar包在同目录下的target文件夹里

5.通过终端切换到该目录下,并执行java -jar demo-0.0.1-SNAPSHOT.jar

o(゚Д゚)っ收工