Springboot项目打包并运行

开始...

1、在上一章的初识springboot博文基础上,新增三个配置文件:
(1).application-dev.yml

server:
  port: 7001

(2).application-test.yml

server:
  port: 7002

(3).application-prod.yml

server:
  port: 7003

2、修改pom的打包方式

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <mainClass>com.kyy.boot.SpringbootApp</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <!--<appendAssemblyId>false</appendAssemblyId>-->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.kyy.boot.SpringbootApp</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

3、打包

mvn -Dmaven.test.skip=true assembly:assembly

4、运行

java -jar kjxb-springboot-1.0-SNAPSHOT.jar -Dspring.profiles.active=prod

...结束

猜你喜欢

转载自blog.51cto.com/11147669/2407999