NutzCN Logo
问答 nutz-book-project5.0下,动态加载jar包问题
发布于 1642天前 作者 shuxinyun 1424 次浏览 复制 上一个帖子 下一个帖子
标签:

我直接用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();
这里返回的是新包中所有的地址映射,不包含原来包带有的。
应用起来后,新包的映射匹配不上,没有任何错误

10 回复

不支持的,5.x没做

目前就是mapping没有引入,是否只要保证NutConfig中的UrlMapping为原来的映射加上新包中的映射就能解决问题

目前加载新包后NutConfig中的UrlMapping就只包含新包的

没那么简单

要是这么简单,你试试搞一下?

@wendal 大神抽时间搞一下呗,需要我做什么我都可以协助,我自己搞着目前没有头绪呀!

我需要你把代码写完,简单吧

思路,给一条思路呀!我之前只是照葫芦画瓢。

那你用3.x不就得了

加点限制条件, 增删的jar不支持@IocBean, 那只应该hotplug插件里面的HotplugUrlMapping, 应该就差不多了

那我先向这个方向研究一下吧

添加回复
请先登陆
回到顶部