使用场景
提供SDK给业务系统,需要给各个不同的业务系统设置不同的配置
PS:借鉴https://blog.csdn.net/qq_40375627/article/details/80301743
实现代码
包含 JarTool类与StringReplace方法接口
@FunctionalInterface
public interface StringReplace {
String process(String srcConf);
}
public class JarTool {
/***
*
* @param jarPath 源jar包路径
* @param newJarPath 新生成的jar存放路径
* @param confPath 需要修改的配置文件相对路径
* @param jarConfChange 配置文件内容替换逻辑
* @return
* @throws IOException
*/
public static final File change(String jarPath,String newJarPath,String confPath,StringReplace jarConfChange) throws IOException {
if(StringUtils.isNotBlank(jarPath)) {
File file = new File(jarPath);
JarFile jarFile = new JarFile(file);
JarEntry entry = jarFile.getJarEntry(confPath.replace("\\", "/"));
List<JarEntry> lists = new LinkedList<JarEntry>();
for (Enumeration<JarEntry> entrys = jarFile.