jar文件:/home/resin.jar
需更新包中com/caucho/server/port/Port.class类文件

方法1:
jar uf resin.jar com/caucho/server/port/Port.class
要求是必须知道jar包的结构要非常熟悉,可以使用:jar tf resin.jar来查看。

方法2:
解压jar xvf resin.jar->覆盖相应类文件->再打包(jar cvf resin.jar com)

假设目录结构是maven标准结构

复制代码代码如下:
-src
-target
-test.jar(你需要更新的jar包)
复制代码代码如下:
package com.foo.common.base.utils.development;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

public class JarUpdater {
 public static final Logger logger = LoggerFactory
   .getLogger(JarUpdater.class);

@Test
 /**
  * 更新com目录下的所有文件到jar的对应目录结构中去
  * 
  * 一次成功的代码更新,我们断言jar的大小是不一样的
  */
 public void updateClass() throws IOException, InterruptedException {

ClassPathResource myPath = new ClassPathResource(
    "jarUpdaterConfig.properties");
  Properties p = new Properties();
  p.load(myPath.getInputStream());

ClassUpdater classUpdater = new ClassUpdater().applySettings(p);

classUpdater.compileAndCopyClass();

String workingDirectory = p.getProperty("workingDirectory");
  String jar4UpdateName = p.getProperty("jar4UpdateName");
  // class compile path
  String updateSourcePath = workingDirectory + "target";
  // class root folder
  String updateSourceDir = "com";

Date startDate = new Date();

File myJar = new File(workingDirectory + jar4UpdateName);
  if (!myJar.isFile()) {
   logger.error("file with following path {} does not exist.",
     jar4UpdateName);
   return;
  }
  long oldLength = myJar.length();
  logger.info("Now ready to update jar file with name:{},size:{}",
    myJar.getName(), myJar.length());
  String myCommand = "jar uf " + workingDirectory + jar4UpdateName
    + " -C " + updateSourcePath + " " + updateSourceDir;
  logger.info("Update command【{}】", myCommand);

Runtime.getRuntime().exec(myCommand);

while (!FileUtils.isFileNewer(myJar, startDate)) {
   logger.info("sleep for two seconds,checking changes...");
   Thread.sleep(2000);
  }
  assertNotEquals(
    "jar may not be updated successfully,check the code please",
    oldLength, myJar.length());
  logger.info("Now finish update jar file with size:{}", myJar.length());
 }
}

更新你的jar包的更多相关文章

  1. Maven 小技巧之 自动更新你的jar包

    在做selenium 自动化测试的时候,我们经常遇到这样的情况:浏览器悄悄升级了.紧接着所有测试用例都Fail. 检查过日志之后发现,原来是升级过的浏览器,我们用原来的selenium已经无法操作. ...

  2. 删除 maven仓库,更新失败的jar包命令

    set REPOSITORY_PATH=D:\maven_cpbsrem ص‎شعثرث÷...for /f "delims=" %%i in ('dir /b /s " ...

  3. maven依赖jar包更新,业务jar需同步更新(业务jar依赖API)

    背景: 环境出现问题,定位为依赖jar缺失,修改工程pom文件补充依赖jar. 更新要点说明: 依赖jar,更新提交 业务jar,也需更新提交:maven构建会把依赖jar引用进去,更新环境如果单独更 ...

  4. 如何更新maven需要的jar包

    第一次使用maven,检出项目生成时出现缺少xxx.jar,目录在C盘下: 拿mybatis-spring-1.2.2.jar来说,发现在C:\Users\Administrator\.m2\repo ...

  5. 贡献你的代码,将jar包发布到Maven中央仓库以及常见错误的解决办法

    前几天将自己的日志工具发布到了Maven中央仓库中.这个工具本省没有多少技术含量,因为是修改别人的源代码实现的,但是将jar发布到Maven仓库却收获颇丰,因为网上有些教程过时了,在此分享下自己发布j ...

  6. 使用Maven命令安装jar包到repo中

    项目中可能会碰到很多jar包,使用maven update不能更新,或者jar包是拷贝过来,不能编译的情况.此时就需要手动使用命令行安装. 例如Demo项目中提示缺少四个jar包,但是在repo中已经 ...

  7. 提取aar 包中的jar包,反编译再替换成新的aar

      参考了 http://blog.csdn.net/hekewangzi/article/details/44676797 针对aar包,增加一些说明 aar包本质应该是zip文件.可以用360解压 ...

  8. 使用Maven命令安装jar包到仓库中

    项目中可能会碰到很多jar包,使用maven update不能更新,或者jar包是拷贝过来,不能编译的情况.此时就需要手动使用命令行安装. 例如Demo项目中提示缺少四个jar包,但是在repo中已经 ...

  9. eclipse maven项目如何将所有的jar包复制到lib目录下?

      1.情景展示 我们知道,maven项目的jar包并不存在于项目当中,项目所需的jar包都保存在本地仓库中,如果本地仓库没有,会从配置的中央仓库下载,如果中央仓库也没有就会报错: 如上图所示,我想将 ...

随机推荐

  1. NodeJs随心学习(一)之UEditor开源项目部署

    作为NodeJs的初学者+6年的码农,我觉得从基础看起太慢了,还是直接上Demo好玩一些. 嗯,直接开玩..今天在GitHub上看到了UEditor之NodeJs版的开源项目激起了我浓厚的兴趣,随后决 ...

  2. 问题解决:form表单的button按钮问题

    最近写了一个KendoUI 的kendowindow组件,组件里包含了一个form表单,表单里有一个button,不是提交保存的按钮,而是链接到另一个kendowindow的按钮,跟请求提交毫无关系, ...

  3. QT宏 Q_OBJECT,explicit, QHostAddress, quint, emit

    QT相關 一. 參考: 1.宏Q_OBJECT 二. explicit struct constrcution 三. QHostAddress Detailed Description: The QH ...

  4. SQLite cans and can'ts

    SQLite 能做的 和 不能做的 1.SQLite_open/SQLite_open_v2

  5. springmvc学习(三)

    第一点---------使用 @RequestMapping 映射请求• Ant 风格资源地址支持 3 种匹配符:?:匹配文件名中的一个字符 *:匹配文件名中的任意字符 **:** 匹配多层路径 @R ...

  6. Android_Json实例

    概要: 最近由于自己的兴趣,想在Android开发一个自己的App,需要使用服务器,所以交换数据是逃不掉了的,但是学生党没有固定的服务器,因此使用的新浪的SAE,在学习的前期下可以尝试一下,挺不错的一 ...

  7. html5 meta头部设置

    <meta name="viewport" content="height=[pixel_value | device-height], width=[pixel_ ...

  8. 【小知识】DataTable 转 List -----------点滴之水,汇涓涓细流,成汪洋大海

    在大部分时候我们从ADO中得到的数据都是DataTable.DataSet数据源,然而有强迫症的同学老是喜欢折腾,硬是要把它转换为实体集合,说是DataTable效率差云云,于是乎收到了同化. 必要信 ...

  9. 边框的css3样式

    一.圆角(border-radius) border-radius:[ <length> | <percentage> ]{1,4} [ / [ <length>  ...

  10. WiFi与WLAN的区别

    很多人到了某一个地方首选要找的就是无线网络,有时候还会问周围的人:这里有WiFi吗?或者说:这里有WLAN吗?那WiFi和WLAN有什么区别呢? 简单来讲,WiFi是无线保真(wireless fid ...