《jdk8u源码分析》11.SetClassPath

src/share/bin/java.c::SetClassPath

static void
SetClassPath(const char *s)
{
    char *def;
    const char *orig = s;
    static const char format[] = "-Djava.class.path=%s";
    /*
     * usually we should not get a null pointer, but there are cases where
     * we might just get one, in which case we simply ignore it, and let the
     * caller deal with it
     */
    if (s == NULL)
        return;
    //展开给定路径通配符,读取并拼接匹配的jar文件路径
    //@see: 9.1.JLI_WildcardExpandClasspath
    s = JLI_WildcardExpandClasspath(s);
    if (sizeof(format) - 2 + JLI_StrLen(s) < JLI_StrLen(s))
        // s is corrupted after wildcard expansion
        return;
    def = JLI_MemAlloc(sizeof(format)
                       - 2 /* strlen("%s") */
                       + JLI_StrLen(s));
    //拼接可选参数:-Djava.class.path=
    sprintf(def, format, s);
    //添加可选参数:-Djava.class.path=
    //@see: 10.AddApplicationOptions
    AddOption(def, NULL);
    if (s != orig)
        JLI_MemFree((char *) s);
}

猜你喜欢

转载自blog.csdn.net/weixin_37477523/article/details/88364342