ぶらコード:maven:その3(Plexusその2):「旅の入り口を発見」の巻
で、以前たどり着いた、「plexus-classworlds-*.jar」が何者かってことから入っていこう。
Plexus Classworlds – About
によると、どうやら「クラスローダーフレームワーク」らしい。
「クラスローダーフレームワーク」って単語はあまり聞きなれないけど、
要はクラスをローディングしてくれる便利ツールなんでしょう。
早速ソースを探す。
Plexus Classworlds – Source Repository
てなページがあったので見てみると、どうやらGitHubでソース管理している様子。
なので以下のURLからソースをゲット。
http://github.com/codehaus-plexus/plexus-classworlds
ローカルで「mvn eclipse:eclipse」してeclipseに取り込む。
でもちょっとその前に、今回の「plexus-classworlds-*.jar」君はjarファイルなので、
このjarの中のどのクラスがエントリポイントなのかを探さないといけない。
jarの中を見てみるのもいいけど、ちょうど良くpom.xmlがあったので、
「jar」というキーワードで検索してみたところ、以下の記述を発見。
<plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.5</version> <configuration> <archive> <manifest> <mainClass>org.codehaus.plexus.classworlds.launcher.Launcher</mainClass> </manifest> </archive> </configuration> </plugin>
pomの記載通り、mainClassは「org.codehaus.plexus.classworlds.launcher.Launcher」らしいので、
こいつのmain()メソッドが今回の旅の入り口(エントリポイント)ってことになるわけだっ。
で、以下のがその入り口です。
/** * Launch the launcher from the command line. * Will exit using System.exit with an exit code of 0 for success, 100 if there was an unknown exception, * or some other code for an application error. * * @param args The application command-line arguments. */ public static void main( String[] args ) { try { int exitCode = mainWithExitCode( args ); System.exit( exitCode ); } catch ( Exception e ) { e.printStackTrace(); System.exit( 100 ); } } /** * Launch the launcher. * * @param args The application command-line arguments. * @return an integer exit code * @throws Exception If an error occurs. */ public static int mainWithExitCode( String[] args ) throws Exception { String classworldsConf = System.getProperty( CLASSWORLDS_CONF ); InputStream is; Launcher launcher = new Launcher(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); launcher.setSystemClassLoader( cl ); 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" ); } launcher.configure( is ); is.close(); try { launcher.launch( args ); } catch ( InvocationTargetException e ) { ClassRealm realm = launcher.getWorld().getRealm( launcher.getMainRealmName() ); URL[] constituents = realm.getURLs(); System.out.println( "---------------------------------------------------" ); for ( int i = 0; i < constituents.length; i++ ) { System.out.println( "constituent[" + i + "]: " + constituents[i] ); } System.out.println( "---------------------------------------------------" ); // Decode ITE (if we can) Throwable t = e.getTargetException(); if ( t instanceof Exception ) { throw (Exception) t; } if ( t instanceof Error ) { throw (Error) t; } // Else just toss the ITE throw e; } return launcher.getExitCode(); }
今回は、入り口をめっけたので、次回はこの入り口をぶらつきつつ、その先に進んで行くとします。