`
kanpiaoxue
  • 浏览: 1781809 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

springboot使用maven-assembly-plugin打包

 
阅读更多

 

参考材料:

1、https://www.cnblogs.com/littleatp/p/9278517.html

2、https://www.jianshu.com/p/3bd850fcb488

 

项目的目录结构:(忽略掉target目录)

helloWorld
├── pom.xml
└── src
    └── main
        ├── assemble
        │   ├── package.xml
        │   └── start.sh
        ├── java
        │   └── org
        └── resources
            ├── application-dev.yml
            ├── application-prod.yml
            ├── application-test.yml
            └── application.yml

 

 

目标 zip 文件的结构:

.
├── config
│   ├── application-dev.yml
│   └── application.yml
├── helloWorld-0.0.1.jar
└── start.sh

 

 

pom.xml

<!-- build start -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>helloWorld</finalName>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>src/main/assemble/package.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>bundle</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<!-- build end -->

<profiles>
    <profile>
        <!-- mvn clean package -Pdev -->
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <environment>dev</environment>
        </properties>
    </profile>
    <profile>
        <!-- mvn clean package -Ptest -->
        <id>test</id>
        <properties>
            <environment>test</environment>
        </properties>
    </profile>
    <profile>
        <!-- mvn clean package -Pprod -->
        <id>prod</id>
        <properties>
            <environment>prod</environment>
        </properties>
    </profile>
</profiles>

 

 

dev/package.xml: 这里只给出了dev 测试环境目录下面的配置,其他的test、prod的在pom.xml的profile中添加一下即可。

<assembly xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
    <id>package</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>

    <fileSets>
        <!-- shell file -->
        <!-- gump job file: ${environment} from pom.xml -->
        <fileSet>
            <directory>src/main/assemble</directory>
            <includes>
                <include>start.sh</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
        <!-- config file: ${environment} from pom.xml -->
        <fileSet>
            <directory>src/main/resources</directory>
            <includes>
                <include>application.yml</include>
                <include>application-${environment}.yml</include>
            </includes>
            <outputDirectory>/config</outputDirectory>
        </fileSet>
        <!-- executable jar -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <includes>
                <include>${project.artifactId}-${project.version}.jar</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

 

 

 打包命令:

mvn clean package -Pdev
#mvn clean package -Ptest
#mvn clean package -Pprod

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics