DefaultLibraries 过滤

基本信息

属性 值
类 com.mitchej123.jarjar.fml.common.DefaultLibraries
来源 Forge 1.12.2-14.23.5.2847 + CoreTweaks
静态判定 已知 JVM/Mojang 类库文件名前缀匹配

DefaultLibraries 维护 42 个已知 jar 文件名前缀,启动期只要路径以 java.home 开头或匹配任一前缀就跳过加载流程,避免 FML 1.7.10 把这些 jar 当作"用户 mod"二次扫描。

列表

final static String[] prefixes = {
    "launchwrapper-", "asm-all-", "akka-actor_2.11-", "config-", "scala-",
    "jopt-simple-", "lzma-", "realms-", "httpclient-", "httpcore-", "vecmath-",
    "trove4j-", "icu4j-core-mojang-", "codecjorbis-", "codecwav-",
    "libraryjavawound-", "librarylwjglopenal-", "soundsystem-", "netty-all-",
    "guava-", "commons-lang3-", "commons-compress-", "commons-logging-",
    "commons-io-", "commons-codec-", "jinput-", "jutils-", "gson-",
    "authlib-", "log4j-api-", "log4j-core-", "lwjgl-", "lwjgl_util-",
    "twitch-", "jline-", "jna-", "platform-", "oshi-core-", "netty-",
    "libraryjavasound-", "fastutil-", "lombok-"
};

判定

public static boolean isDefaultLibrary(File file) {
    final String home = System.getProperty("java.home");
    if (home != null && file.getAbsolutePath().startsWith(home)) return true;
    final String name = file.getName();
    if (!name.endsWith(".jar")) return false;
    for (int i = 0; i < prefixes.length; i++) {
        if (name.startsWith(prefixes[i])) return true;
    }
    return false;
}

判定顺序:

  1. 路径以 java.home 开头 → 是默认库
  2. 文件名不以 .jar 结尾 → 不是默认库
  3. 命中任一前缀 → 是默认库
  4. 否则 → 不是默认库

使用点

  • ClasspathModCandidateFinder.findCandidates:跳过这些 jar 不当作 classpath mod 加载
  • Hooks.shouldIgnore:CCC ClassDiscoverer 通过该 hook 复用此列表

与 ClasspathModCandidateFinder 协作

List<String> knownLibraries = ImmutableList.<String>builder()
    .addAll(modClassLoader.getDefaultLibraries())  // Forge 原生默认库(部分 jvm 系)
    .addAll(CoreModManager.getLoadedCoremods())    // 已加载的 coremod jar
    .addAll(CoreModManager.getReparseableCoremods())
    .build();

DefaultLibraries 用于在该列表之外的 jar 上做第二次过滤:

if (knownLibraries.contains(minecraftSources[i].getName()) || DefaultLibraries.isDefaultLibrary(minecraftSources[i])) {
    FMLLog.finer("Skipping known library file %s", minecraftSources[i].getAbsolutePath());
}

相关条目