用代码更新你的jar包
发布时间:2023-09-19 23:01:04
假设目录结构是maven标准结构
-srcpackage com.foo.common.base.utils.development;
-target
-test.jar(你需要更新的jar包)
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());
}
}
猜你喜欢
- 在style中如下面那样定义:<style name="mystyle"> <item name=&
- 初次安装Android Studio,遇到了不少问题,这是其中的一个,分享如下,同时求各位dalao关注一下啦((*^__^*) )使用不同
- CSRF介绍CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click atta
- C# 关于Invoke首先说下,invoke和begininvoke的使用有两种情况:control中的invoke、begininvoke
- Android中获取资源 id 及资源 id 的动态获取我们平时获取资源是通过 findViewById 方法进行的,比如我们常
- 前言我们在 页面切换转场动画,英雄救场更有趣!介绍了 Hero 动画效果,使用 Hero 用于转场能够提供非常不错的体验。既然称之
- 导语:有些时候我们所需要查询的数据量比较大,但是jvm内存又是有限制的,数据量过大会导致内存溢出。这个时候就可以使用流式查询,数据一条条的返
- 具体可见http://developer.android.com/tools/debugging/ddms.html。 DDMS为IDE和e
- 方法参数public String listFireEvent(@Valid FireSearch fireSearch, Ht
- 前言CompletableFuture实现了CompletionStage接口和Future接口,前者是对后者的一个扩展,增加了异步回调、流
- 该工具包含是封装了jedis,包含redis.properties和jedisPool,序列化使用的是protostuff,map类型操作使
- 使用AS创建ADIL文件时AS会在main文件夹下给我们生成一个aidl文件夹和一个相同包名的包,通常我们会把所有和ADIL相关的类或文件放
- MyBatis 通过包含的jdbcType类型BIT FLOAT CHAR &nbs
- HashMap和HashTable,这二者的区别经常被别人问起,今天在此总结一下。(一)继承的历史不同public class
- 前言当系统的并发比较高的时候,日志的处理输出也是一种性能的开销负担,所以,选择一个中间件来处理消费日志必不可少!下面是spring boot
- jpa EntityManager复杂查询概念EntityManager:EntityManager是JPA中用于增删改查的接口,它的作用相
- Android手势解锁本文讲述的是一个手势解锁的库,可以定制显示隐藏宫格点、路径、并且带有小九宫格显示图,和震动!让你学会使用这个简单,高效
- Java Function的使用一、方法介绍表示接受一个参数并产生结果的函数。参数类型 T - 函数输入的类型R - 函数的结果类型方法介绍
- 首先引入pom <!--SpringBoot 2.1.0--> <parent>  
- 前言这里主要简单介绍如何使用Camera+SurfaceView自定义相机拍照,如果是Camera2或者是TextureView的可以前往主