Spring项目打包部署( Maven Assembly插件)

一、Maven Assembly插件 打包

为了在服务器上部署项目,需要将代码打包,其目录结构如下:
/bin 执行启动或停止的脚本
/conf 配置文件所在
/lib 代码的jar包以及所依赖的jar包
/webapp 与项目的webapp相同

为了能够打包,我们需要使用assembly插件,pom.xml配置如下:

     <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <descriptor><!--配置文件所在 -->
                src/main/assembly/assembly.xml</descriptor>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
                <goals>
                    <goal>single</goal><!-- 只运行一次 -->      
                </goals>
            </execution>
        </executions>
    </plugin>

下面看一下详细的配置文件assembly.xml:


<assembly>
    <id>assembly</id>
    <formats>
 <!--format设置包输出的格式,当前格式设置的为tar.gz格式,目前还支持zip,tar,tar.gz,tar.bz2,jar,dir,war格式  -->
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
    <!--fileSet定义代码目录中与输出目录的映射-->
        <fileSet>
            <directory>src/main/assembly/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/conf</directory>
            <outputDirectory>conf</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/webapp</directory>
            <outputDirectory>webapp</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
    </fileSets>
    <!--dependencySets节点下为依赖设置-->
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

不管是在命令行还是在IDE中进行相应的Maven install 操作,会把这个项目打出一个tar包,然后 将其部署到服务器就可以了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值