diff --git a/src/META-INF/application-template.xml b/src/META-INF/application-template.xml index 69353f8b1..a9310c33a 100644 --- a/src/META-INF/application-template.xml +++ b/src/META-INF/application-template.xml @@ -79,7 +79,8 @@ host: 服务所占address , 默认: 0.0.0.0 port: required 服务所占端口 root: 如果是web类型服务,则包含页面 默认:{APP_HOME}/root - lib: server额外的class目录, 默认为空 + lib: server额外的class目录, 默认为空 + excludelibs: 排除lib.path与excludes中的正则表达式匹配的路径, 多个正则表达式用分号;隔开 charset: 文本编码, 默认: UTF-8 backlog: 默认10K threads: 线程总数, 默认: CPU核数*16 diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index 1b6cf69dc..7f4e48d71 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -475,7 +475,7 @@ public final class Application { synchronized (nodeClasses) { if (!inited.getAndSet(true)) { //加载自定义的协议,如:SOCKS ClassFilter profilter = new ClassFilter(NodeProtocol.class, NodeServer.class); - ClassFilter.Loader.load(home, profilter); + ClassFilter.Loader.load(home, serconf.getValue("excludelibs", "").split(";"), profilter); final Set> entrys = profilter.getFilterEntrys(); for (FilterEntry entry : entrys) { final Class type = entry.getType(); diff --git a/src/org/redkale/boot/ClassFilter.java b/src/org/redkale/boot/ClassFilter.java index f264a2688..2f52a9d74 100644 --- a/src/org/redkale/boot/ClassFilter.java +++ b/src/org/redkale/boot/ClassFilter.java @@ -421,18 +421,30 @@ public final class ClassFilter { /** * 加载当前线程的classpath扫描所有class进行过滤 * - * @param exclude 不需要扫描的文件夹, 可以为null - * @param filters 过滤器 + * @param excludeFile 不需要扫描的文件夹, 可以为null + * @param excludeRegs 包含此关键字的文件将被跳过, 可以为null + * @param filters 过滤器 * * @throws IOException 异常 */ - public static void load(final File exclude, final ClassFilter... filters) throws IOException { + public static void load(final File excludeFile, final String[] excludeRegs, final ClassFilter... filters) throws IOException { URLClassLoader loader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); List urlfiles = new ArrayList<>(2); List urljares = new ArrayList<>(2); - final URL exurl = exclude != null ? exclude.toURI().toURL() : null; + final URL exurl = excludeFile != null ? excludeFile.toURI().toURL() : null; + final Pattern[] excludePatterns = toPattern(excludeRegs); for (URL url : loader.getURLs()) { if (exurl != null && exurl.sameFile(url)) continue; + if (excludePatterns != null) { + boolean skip = false; + for (Pattern p : excludePatterns) { + if (p.matcher(url.toString()).matches()) { + skip = false; + break; + } + } + if (skip) continue; + } if (url.getPath().endsWith(".jar")) { urljares.add(url); } else { @@ -477,7 +489,7 @@ public final class ClassFilter { files.clear(); File root = new File(url.getFile()); String rootpath = root.getPath(); - loadClassFiles(exclude, root, files); + loadClassFiles(excludeFile, root, files); for (File f : files) { String classname = f.getPath().substring(rootpath.length() + 1, f.getPath().length() - 6).replace(File.separatorChar, '.'); if (classname.startsWith("javax.") || classname.startsWith("com.sun.")) continue; diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java index 3788a5597..99ed70e51 100644 --- a/src/org/redkale/boot/NodeServer.java +++ b/src/org/redkale/boot/NodeServer.java @@ -27,32 +27,6 @@ import org.redkale.service.*; import org.redkale.source.*; import org.redkale.util.AnyValue.DefaultAnyValue; import org.redkale.util.*; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; -import static java.lang.Class.forName; /** * Server节点的初始化配置类 @@ -200,9 +174,9 @@ public abstract class NodeServer { ClassFilter serviceFilter = createServiceClassFilter(); long s = System.currentTimeMillis(); if (servletFilter == null) { - ClassFilter.Loader.load(application.getHome(), serviceFilter); + ClassFilter.Loader.load(application.getHome(), serverConf.getValue("excludelibs", "").split(";"), serviceFilter); } else { - ClassFilter.Loader.load(application.getHome(), serviceFilter, servletFilter); + ClassFilter.Loader.load(application.getHome(), serverConf.getValue("excludelibs", "").split(";"), serviceFilter, servletFilter); } long e = System.currentTimeMillis() - s; logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");