Launcher launcher = new Launcher();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
launcher.setSystemClassLoader( cl );
上記の1行目で、Launcherクラスのインスタンスを生成している。そのコンストラクタが以下。
よく見ると、コンストラクタの中でThread.currentThread().getContextClassLoader()した結果を、this.systemClassLoaderに設定しているので、2行目と3行目は冗長。意図を明確にするためにわざとやってんのかも?
public Launcher()
{
this.systemClassLoader = Thread.currentThread().getContextClassLoader();
}
そんでもって、Launcher#setSystemClassLoader()メソッドの定義がこちら
public void setSystemClassLoader( ClassLoader loader )
{
this.systemClassLoader = loader;
}
なんで、コンテキストローダを保存しているのかというと、ちょっと気になったので、先回りしてみてきたところ、他のクラスローダを使ってクラスをロードする処理があるからのようだ。一度他のクラスローダに切り替えた後に、元に戻すために、ここで保存しているということだと思われる。
次はclassworlds.confを読み込む処理。起動時に-Dclassworlds.confにファイルへのパスを設定してた場合は、以下のif節に入る。
そうでない場合は、else節に入る。else節では、classworlds.bootstrappedというプロパティ値をシステムプロパティから読み込んんでいるので、これが設定されている場合は、所定のパスから読み込むようになっているようだ。所定のパスというのは、「UBERJAR_CONF_DIR + CLASSWORLDS_CONF」のことで、UBERJAR_CONF_DIRは「WORLDS-INF/conf/"」と定義されている。
if ( classworldsConf != null )
{
is = new FileInputStream( classworldsConf );
}
else
{
if ( "true".equals( System.getProperty( "classworlds.bootstrapped" ) ) )
{
is = cl.getResourceAsStream( UBERJAR_CONF_DIR + CLASSWORLDS_CONF );
}
else
{
is = cl.getResourceAsStream( CLASSWORLDS_CONF );
}
}
if ( is == null )
{
throw new Exception( "classworlds configuration not specified nor found in the classpath" );
}
さらに、classworlds.bootstrappedも定義されていない場合は、「cl.getResourceAsStream( CLASSWORLDS_CONF )」としているので、このクラスローダのクラスパスのどこかからファイルを探してくるようだな。それでも見つからなかった場合は、例外をスローしている。
ここまでで、設定ファイルclassworlds.confが読み込めたので、次にこのファイルから実際に値を読み込んで行くのだろう。
launcher.configure( is );