Springboot使用Maven打包

spring-boot-maven-plugin

		  <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

这是我们最常见的springboot打包方法,但是使用spring-boot-maven-plugin打包是打成整包发布,依赖的jar与我们的代码包是放在一起发布的,更换部署是很麻烦的。而且你会发现,发布包的主类是Springboot封装之后的。

maven-jar-plugin

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<archive>
						<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
						<!-- <index>true</index> -->
						<manifest>
							<mainClass>cn.maritech.dss.DSS</mainClass>
							<addClasspath>true</addClasspath>
							<classpathPrefix>../libs/</classpathPrefix>
						</manifest>
						<!--<manifestEntries>-->
						<!--<Class-Path>../resources</Class-Path>-->
						<!--</manifestEntries>-->
					</archive>
					<excludes>
						<exclude>data/**</exclude>
						<exclude>static/**</exclude>
						<exclude>templates/**</exclude>
						<exclude>*.txt</exclude>
						<exclude>*.xml</exclude>
						<exclude>*.properties</exclude>
					</excludes>
				</configuration>
			</plugin>

这是目前是使用的打包方法。也就是maven jar打包方法,不同的是将前端资源也打包进去。方法比较老派,但是很好用。Spingboot的jar还是作为依赖库使用。结合maven-assembly-plugin形成部署态文件夹。

maven-assembly-plugin没有任何编译功能,这东西就是文件迁移、做文件夹用的。

			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<!--jar包名称-->
					<finalName>${project.artifactId}-${project.version}</finalName>
				</configuration>
				<executions>
					<execution>
						<id>full</id>
						<!-- 绑定到package生命周期阶段上 -->
						<phase>package</phase>
						<goals>
							<!-- 只运行一次 -->
							<goal>single</goal>
						</goals>
						<configuration>
							<!--描述文件路径-->
							<descriptor>${basedir}/assembly/assembly.xml</descriptor>
						</configuration>
					</execution>
				</executions>
			</plugin>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
          http://maven.apache.org/xsd/assembly-2.0.0.xsd
            http://maven.apache.org/ASSEMBLY/2.0.0 ">
    <!--这个id会跟在打包文件后面,现还不清楚怎么取消-->
    <id>release</id>
    <formats>
        <format>dir</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>libs</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>

    <fileSets>


        <fileSet>
            <directory>${project.basedir}\data</directory>
            <outputDirectory>data</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>${project.basedir}\src\main\resources</directory>
            <outputDirectory>resources</outputDirectory>
            <!--<includes>-->
            <!--<include>*.xml</include>-->
            <!--<include>*.properties</include>-->
            <!--</includes>-->
        </fileSet>


        <fileSet>
            <directory>${project.basedir}/wrapper</directory>
            <outputDirectory>bin</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>${project.basedir}/jre</directory>
            <outputDirectory>jre</outputDirectory>
        </fileSet>


        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>


        <fileSet>
            <directory>${project.basedir}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

参考链接
http://www.cnblogs.com/gannalyo/p/9681567.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值