1.由于所有的项目最终都需要通过maven来进行发布与打包处理,所以在services项目里面要进行一个新的源程序的目录配置, 目录的名称:src/main/bin;(源代码操作目录中)
2.将通过dubbo-2.5.3.jar(dubbo-2.5.3.jar\META-INF\assembly\bin)文件里拷贝出来的所有可执行程序放到目录(src/main/bin)之中;
3.最终打包完成之后项目会部署到liunx之中,那么肯定就希望程序可以以一个压缩文件的形式出现(tar.gz),既然是我们压缩文件 那么对于一些核心的配置目录:bin,conf,lib 就需要做一个打包的配置;所以再次建立一个源文件目录:src/main/assembly;
4.在部署“src/main/assembly” 目录之中创建一个部署的配置文件:assembly.xml;
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<!-- <id>release</id> -->
<formats> <!-- 打包的文件格式 tar.zip war zip -->
<format>tar.gz</format> <!-- 生成压缩文件 -->
<format>dir</format> <!-- 将打包的程序归档到一个目录之中 -->
</formats>
<includeBaseDirectory>false</includeBaseDirectory> <!-- zip包里直接就是bin等子目录,不包括artifactId这层目录 -->
<fileSets>
<fileSet>
<directory>src/main/resources</directory><!-- 需要打包的路径 -->
<outputDirectory>conf</outputDirectory> <!-- 打包后输出的路径 -->
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>${profile.dir}</directory>
<outputDirectory>conf</outputDirectory>
<filtered>true</filtered>
<includes>
<include>logback.xml</include>
<include>config/*.properties</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>src/main/bin</directory> <!-- 将src/main/bin目录下的文件打包到根目录(/bin)下. -->
<outputDirectory>/bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<!-- 依赖包打包到目录下 -->
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact> <!-- 当前项目构件是否包含在这个依赖集合里 -->
<outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
5.随后还需要修改service/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>
6.那么现在一切的准备都到位了,随后解决的问题就在于要进行项目的打包,而本次的项目 一共有三个,parent,remoteapi,service 也需要进行打包; parent,remoteapi :clean package serice : clean package (clean package -P dev) 打包services程序的时候一定要考虑好使用的profile问题,默认配置为dev
7.打包之后会将所以的内容都进行打包处理,很明显,就会在*.jar文件里出现有重复的配置文件,这个问题在直接使用的时候就非常明显了,所以为了解决这样的问题,需要针对于打包 的插件做一个排除配置,修改service项目的pom.xml文件修改:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<!-- 排除jar包文件 -->
<excludes>
<exclude>config/</exclude>
<exclude>META-INF/</exclude>
<exclude>logback.xml</exclude>
</excludes>
</configuration>
</plugin>