我直接用3.0的引用代码方式出现问题,然后做了一个新类:
public class AppHotplug extends Hotplug {
private UrlMapping urlMapping;
public AppHotplug() throws IOException {
super();
this.config=EP.NutConfig;
this.ioc=EP.Ioc;
}
public HotplugConfig loadJar(File jar) throws Exception {
HotplugConfig config=this.getConfig(jar);
this.enable(jar,config);
UrlMapping mapping=config.getUrlMapping();
return config;
}
public HotplugConfig getConfig(File f) {
try {
ZipFile zf = new ZipFile(f);
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zf.entries();
HotplugConfig hc = null;
try {
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
String name = ze.getName();
if (name.endsWith("/"))
continue;
if (name.startsWith("hotplug/hotplug.") && name.endsWith(".json")) {
String j = new String(Streams.readBytes(zf.getInputStream(ze)));
hc = Json.fromJson(HotplugConfig.class, j);
hc.put("origin", "file");
hc.put("origin_path", f.getAbsolutePath());
hc.put("sha1", Lang.sha1(f));
hc.put("enable", new File(f.getParentFile(), f.getName() + ".enable").exists());
return hc;
}
else if (name.startsWith("custom/") && name.endsWith(".properties")) {
InputStream ins=zf.getInputStream(ze);
if(ins!=null){
Properties conf = new Properties();
conf.load(ins);
for(String key:conf.stringPropertyNames()){
EP.getProperties().put(key,conf.getProperty(key));
}
}
}
}
}
finally {
zf.close();
}
}
catch (Exception e) {
return null;
}
return null;
}
}
然后通过loadJar动态加载jar项目,项目引入其他正常,就是入口URL映射不识别。
UrlMapping mapping=config.getUrlMapping();
这里返回的是新包中所有的地址映射,不包含原来包带有的。
应用起来后,新包的映射匹配不上,没有任何错误