项目改成了maven管理,现场需要用增量补丁包的形式发布代码;

2015/4/21

以前试过用ant打补丁包,现在试试maven能不能做同样的事情;

maven-assembly-plugin看着可以做这样的事情;http://www.infoq.com/cn/news/2011/06/xxb-maven-9-package/

pom.xml配置:

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

assembly.xml:

<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<includes>
<include>README.txt</include>
</includes>
</fileSet>
<!-- <fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>run.sh</include>
<include>run.bat</include>
</includes>
</fileSet> -->
</fileSets>
</assembly>

运行maven clean package;

第一次运行要下载很多包;

看看srpm-bin.zip都有什么;

lib里边是所有依赖jar和war包;

现在要的是只打包部分class和配置,不需要打包依赖和不生成war包;

看看怎么配置:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

/controllers/HomeController*.class

配置加了通配符*,没生效;

[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml

[WARNING] The following patterns were never triggered in this artifact inclusion filter:

哈哈,这里只是用fileSet就可以了;

增加一个试试:

<fileSet>

<outputDirectory>/WEB-INF/classes</outputDirectory>

<includes>

<include>target/classes/com/xxx/srpm/controllers/HomeController.class</include>

</includes>

</fileSet>

打包结果路径是:

WEB-INF\classes\target\classes\com\xxx\srpm\controllers

需要的是:

WEB-INF\classes\com\xxx\srpm\controllers

因为这样和war包的目录结构一样,升级的时候直接拖动文件夹覆盖war包里边的就可以了;

看文档貌似directory能设置基准路径;

<fileSet>

<outputDirectory>/WEB-INF/classes</outputDirectory>

<directory>target/classes/</directory>

<includes>

<include>com/xxx/srpm/controllers/HomeController.class</include>

</includes>

</fileSet>

完美!就是这样配置了;

完整的配置如下:

<assembly>
<id>upd-20150421-1</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/WEB-INF/classes</outputDirectory>
<directory>target/classes/</directory>
<includes>
<include>com/xxx/srpm/controllers/HomeController.class</include>
<include>com/xxx/srpm/activiti/DetailBuilder.class</include>
<include>com/xxx/srpm/activiti/common/HistoricProcessInstanceSQLFragment.class</include>
<include>com/xxx/srpm/activiti/query/HistoricProcessInstanceQuery.class</include>
<include>com/xxx/srpm/base/dao/BaseDao.class</include>
<include>com/xxx/srpm/base/dao/SQL.class</include>
<include>com/xxx/srpm/base/query/BaseQuery.class</include>
<include>com/xxx/srpm/base/util/BaseUtils.class</include>
<include>com/xxx/srpm/base/util/PageUtils.class</include>
<include>com/xxx/srpm/repository/activiti/HistoricProcessInstanceRepository.class</include>
</includes>
</fileSet>
<fileSet>
<outputDirectory>/</outputDirectory>
<includes>
<include>README.txt</include>
</includes>
</fileSet>
</fileSets>
</assembly>

再写个Helper:

/**
* assembly.xml配置工具类
* @author yejq
*/
public class AssemblyHelper { private final static String CLASS_PATH; static {
File file = new File("");
CLASS_PATH = file.getAbsolutePath();
} /**
* 将java的路径转换为class路径
*/
@Test
public void java2class(){
String path = CLASS_PATH + "/src/test/java/build/java.txt";
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(path));
String line = null;
StringBuilder builder = new StringBuilder();
while ((line = reader.readLine()) != null) {
if (StringUtils.isNotBlank(line)) {
line = line.trim().replace("/srpm/src/main/java/", " <include>")
.replace(".java", ".class</include>");
builder.append(line).append(BaseUtils.lineSeparator);
}
}
System.out.println(builder.toString());
} catch (Exception e) {
e.printStackTrace();
}finally{
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

maven-assembly-plugin挺好用,好强大!

再加上个通配符,避免遗漏内部类;

<include>com/xxx/srpm/controllers/HomeController*.class</include>

总结:

1、解决方案很多,用哪个,究竟哪个更适合更优雅,用过才知道,或许不是最佳实践,但没试过,怎么知道是不是最佳呢?这就是架构做的事情:在解决方案之间做决策,并提供最佳实践,指导开发人员实践;

2、工作了一周,问同事有没有签合同,了解到可能是转正签,之前遇到的都是入职签,这转正签会不会有问题?

测试发布(maven-assembly-plugin看好你哦)的更多相关文章

  1. 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用

    今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...

  2. maven assembly plugin使用

    使用场景 在使用maven来管理项目时,项目除了web项目,还有可能为控制台程序,一般用于开发一些后台服务的程序.最近在工作中也遇到了这种场景,使用quartz开发一个任务调度程序.程序中依赖很多ja ...

  3. 使用Maven Assembly plugin将依赖打包进jar

    一个Eclipse的工程,在pom中配置了若干依赖,需要将pom中所有的依赖全部打包进一个jar包中,可以选择的方案有maven-assembly-plugin和fatjar.以前采用fatjar进行 ...

  4. Maven Assembly插件介绍

    转自:http://blueram.iteye.com/blog/1684070 已经写得挺好的,就不用重写了. 你是否想要创建一个包含脚本.配置文件以及所有运行时所依赖的元素(jar)Assembl ...

  5. maven assembly 配置详解

    Maven Assembly插件介绍 博客分类: 项目构建   你是否想要创建一个包含脚本.配置文件以及所有运行时所依赖的元素(jar)Assembly插件能帮你构建一个完整的发布包. Assembl ...

  6. [原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...

  7. Gitlab+Jenkins学习之路(八)之发布maven项目及按版本发布

    一.什么是Maven maven是一个项目管理和综合工具.Maven提供给开发人员构建一个完整的生命周期框架. 开发团队可以自动完成该项目的基础设施建设,Maven使用标准的目录结构和默认构建生命周期 ...

  8. 学习Maven之Maven Enforcer Plugin

    1.Maven Enforcer plugin是什么鬼? 在说这个插件是什么前我们先思考这么一个问题:当我们开发人员进入项目组进行开发前,要准备开发环境,而领导总是会强调工具的统一,编译环境的统一.比 ...

  9. maven jetty plugin

    转载:http://blog.163.com/xueling1231989@126/blog/static/1026408072013101311395492/ 前言: 在 maven 下测试调试时, ...

  10. 如何发布Maven依赖到中央仓库

    平时我们都是从Maven中央仓库下载依赖,如果我们想发布我们自己写的Maven依赖到中央仓库供别人下载使用应该怎么办?这里以上传自己写的simian-maven-plugin(https://gith ...

随机推荐

  1. SQL Server 练习

    use master if exists(select * from sys.databases where name='db_Test') drop database db_Test go crea ...

  2. 浅谈JavaScript--事件委托与事件监听

    事件监听 该方法用于向指定元素添加事件句柄(代码块),且不会覆盖已存在的事件句柄. 即可以向同一个元素添加同一个事件多次. 添加事件 语法: element.addEventListener(even ...

  3. Codeforces Round #558 (Div. 2)B(SET,模拟)

    #include<bits/stdc++.h>using namespace std;int a[100007];int cnt[100007];int main(){    int n; ...

  4. java 提取(解压)rar文件中特定后缀的文件并保存到指定目录

    内容简介 本文主要介绍使用junrar来提取rar压缩文件中特定后缀(如:png,jpg)的文件并保存到指定目录下. 支持v4及以下版本压缩文件,不支持v5及以上. 在rar文件上右键,查看属性,在压 ...

  5. jpanel使用布局管理器时,setsize会失效

    布局管理器会自动根据容器里面的控件大小自动调整size和位置 如果想设置容器的大小和位置,可以使用setPreferredSize方法.

  6. QuotaExceededError: The quota has been exceeded. localStorage缓存超出限制

    今天在项目中遇到了一个问题,localStorage存储超出限制.报错信息如标题.这个是因为最近做了一波优化,把导航栏和一些用户信息本地化存储,都放在localStorage里,也不是每个用户会出现这 ...

  7. Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)

    A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. kubectl 命令

    Kubectl 命令表 kubectl run kubectl expose kubectl annotate kubectl autoscale kubectl convert kubectl cr ...

  9. lynis检测

    https://www.cnblogs.com/ssooking/p/6034402.html Usage: lynis command [options] Command: audit audit ...

  10. html_entity_decode与htmlentities函数

    htmlentities() 函数把字符转换为 HTML 实体.html_entity_decode() 函数把 HTML 实体转换为字符.例子:$a = '<div> <p> ...