idea maven assembly plugin 使用

 

安装监控中心:

1、dubbo官网源码下载 地址:https://github.com/apache/incubator-dubbo.git

2、cd  /${path}/dubbo-simple/dubbo-monitor-simple

mvn clean install -DskipTests=true  //win  需要配置maven

3、打包后的目录  进入target里面找到.   xxx.tar.gz  解压  解压后里面有bin  conf  lib   //windows无法解压tar.gz

4、将bin  conf 复制到项目中 

dubbo.properties配置


##
# Copyright 1999-2011 Alibaba Group.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
dubbo.container=log4j,spring,registry,jetty
dubbo.application.name=simple-monitor
dubbo.application.owner=
#dubbo.registry.address=multicast://224.5.6.7:1234
#配置zookeeper
dubbo.registry.address=zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182,127.0.0.1:2183
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.protocol.port=7070     
dubbo.jetty.port=9090
dubbo.jetty.directory=${user.home}/monitor
dubbo.charts.directory=${dubbo.jetty.directory}/charts
dubbo.statistics.directory=${user.home}/monitor/statistics
dubbo.log4j.file=logs/dubbo-monitor-simple.log
dubbo.log4j.level=WARN

Maven的assembly插件实现自定义打包

assembly.xml的配置项非常多,可以参考http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
以上只是用了很少的一部分。
format设置包输出的格式,以上格式设置的为zip格式,目前还支持zip,tar,tar.gz,tar.bz2,jar,dir,war格式
fileSet定义代码目录中与输出目录的映射,在该节点下还有 <includes/>,<excludes/>两个非常有用的节点。
比如:(本项目用的第2个配置)

1、打包管理中心用的

这个是配置管理中心用到的
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <!--该字符会添加到最终tar.gz包的名称后面做后缀-->
    <id>assembly</id>
    <!--指定打包个事为tar.gz.该类型压缩包在Linux中常见-->
    <formats>
        <format>tar.gz</format>
    </formats>
    <!--在tar.gz压缩包中是否包含根文件夹,改根文件夹名称和tar.gz去掉id后缀一致-->
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <!--建项目根路径下assembly/bin路径中的内容打包到压缩包中的根目录下的bin目录中-->
        <fileSet>
            <!--相对项目根路径的相对路径-->
            <directory>assembly/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <!--设置最终tar.gz中改文件夹下的权限,跟linux权限写法一直-->
            <fileMode>0755</fileMode>
        </fileSet>
        <!--将项目根路径下assembly/conf路径中的内容打包到压缩包中的根目录下的conf目录中-->
        <fileSet>
            <directory>assembly/conf</directory>
            <outputDirectory>conf</outputDirectory>
            <!--设置linux权限-->
            <fileMode>0644</fileMode>
        </fileSet>
    </fileSets>
    <!--将所有依赖的jar包打包到压缩包中的根目录下的lib目录中-->
    <!--此lib目录中包含自己开发的项目jar包以及demo_service.jar还有第三方的jar包-->
    <dependencySets>
        <dependencySet>
            <!--<useProjectArtifact>true</useProjectArtifact>-->
            <outputDirectory>lib</outputDirectory>            <!-- 将scope为runtime的依赖包打包到lib目录下。 -->
            <!--<scope>runtime</scope>-->
        </dependencySet>
    </dependencySets>
</assembly>

2、打包项目用java -jar xxx.jar发布服务要用到的 

这个是配置依赖包  本项目这个
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
    <id></id>
    <formats>
        <format>tar.gz</format><!--打包的文件格式,也可以有:war zip-->
    </formats>
    <!--tar.gz压缩包下是否生成和项目名相同的根目录-->
    <includeBaseDirectory>true</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <!--是否把本项目添加到依赖文件夹下-->
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <!--将scope为runtime的依赖包打包-->
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>assembly/bin</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

6、打包完成后,我们可以看到bin目录来存放启动脚本等文件,config为配置文件,lib下为运行时依赖的jar包。
使用maven assembly插件需要在pom文件中配置,添加这个插件(发布项目用2个、打包管理中心用第1、个)

1、打包管理中心

 <build>
        <plugins>        
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <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>
        </plugins>
    </build>

2、部署项目

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <!--运行jar包时运行的主类,要求类全名-->
                            <mainClass>com.util.Provider</mainClass>
                            <!-- 是否指定项目classpath下的依赖 -->
                            <addClasspath>true</addClasspath>
                            <!-- 指定依赖的时候声明前缀 -->
                            <classpathPrefix>./</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution><!-- 配置执行器 -->
                        <id>make-assembly</id>
                        <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
                        <goals>
                            <goal>single</goal><!-- 只运行一次 -->
                        </goals>
                        <configuration>
                            <finalName>${project.name}</finalName>
                            <descriptor>assembly/assembly.xml</descriptor><!--配置描述文件路径-->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

7、编译打包

8、打包完毕   解压到你想要解压的地方  (这个是管理中心配图)

项目部署配图  看ego_service_impl.tar.gz

java -jar xxx.jar &    //linux下启动jar   &表示后台运行
更多节点的用法可以去官网查询
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

下面的文章会介绍打包后的包如何做成windows服务,linux服务。

参考资料

http://maven.apache.org/plugins/maven-assembly-plugin/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值