美文网首页
maven3 springboot 几种打包构建方法 assem

maven3 springboot 几种打包构建方法 assem

作者: 淼哥1986 | 来源:发表于2020-04-06 19:34 被阅读0次
    1. all in one
    <build>
            <finalName>demo</finalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <fork>true</fork>
                        <mainClass>com.example.demo.DemoApplication</mainClass>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    启动

    java -jar demo.jar
    

    2.个性化,配置文件和jar包分离
    pom文件

    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>src/main/resources</directory>
                                        <filtering>false</filtering>
                                    </resource>
                                </resources>
                                <outputDirectory>${basedir}/target/demo/conf/</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>distro-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptors>
                                    <descriptor>assembly.xml</descriptor>
                                </descriptors>
                                <outputDirectory>target</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    

    assembly.xml

    <assembly>
        <id>distribution</id>
        <formats>
            <format>tar.gz</format>
        </formats>
        <fileSets>
            <fileSet>
                <directory>${basedir}/target/demo/lib</directory>
                <outputDirectory>/lib</outputDirectory>
            </fileSet>
            <fileSet>
                <directory>${basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>package</exclude>
                </excludes>
                <outputDirectory>/conf</outputDirectory>
            </fileSet>
        </fileSets>
        <!-- jar -->
        <dependencySets>
            <dependencySet>
                <useProjectArtifact>true</useProjectArtifact>
                <outputDirectory>lib</outputDirectory>
                <scope>runtime</scope>
            </dependencySet>
        </dependencySets>
    </assembly>
    

    linux下启动

    java -server -cp conf:.:lib/* com.example.demo.DemoApplication
    

    小窍门,可通过如下命令拼依赖的jar包,可调整jar包依赖顺序

    echo *.jar | tr ' ' ':'
    

    相关文章

      网友评论

          本文标题:maven3 springboot 几种打包构建方法 assem

          本文链接:https://www.haomeiwen.com/subject/ibfiphtx.html