@@ -27,17 +27,20 @@ private static Method getAddURL() {
2727 *
2828 * @param jarbase Ex: "scalive-agent", not "scalive-agent-1.0.jar"
2929 */
30- public static String findJar (String jarpath , String jarbase ) throws Exception {
31- File dir = new File (jarpath );
32- File [] files = dir .listFiles ();
30+ public static String findJar (String [] jarpaths , String jarbase ) throws Exception {
31+ for (String jarpath : jarpaths ) {
32+ File dir = new File (jarpath );
33+ File [] files = dir .listFiles ();
3334
34- for (int i = 0 ; i < files .length ; i ++) {
35- File file = files [i ];
36- String name = file .getName ();
37- if (file .isFile () && name .endsWith (".jar" ) && name .startsWith (jarbase ))
38- return file .getPath ();
35+ for (int i = 0 ; i < files .length ; i ++) {
36+ File file = files [i ];
37+ String name = file .getName ();
38+ if (file .isFile () && name .endsWith (".jar" ) && name .startsWith (jarbase ))
39+ return file .getPath ();
40+ }
3941 }
40- throw new Exception ("Could not find " + jarbase + " in " + jarpath );
42+
43+ throw new Exception ("Could not find " + jarbase + " in " + join (jarpaths , File .pathSeparator ));
4144 }
4245
4346 public static void addPath (URLClassLoader cl , String path ) throws Exception {
@@ -46,36 +49,40 @@ public static void addPath(URLClassLoader cl, String path) throws Exception {
4649 }
4750
4851 /** Combination of findJar and addPath. */
49- public static void findAndAddJar (URLClassLoader cl , String jarpath , String jarbase ) throws Exception {
50- String jar = findJar (jarpath , jarbase );
52+ public static void findAndAddJar (URLClassLoader cl , String [] jarpaths , String jarbase ) throws Exception {
53+ String jar = findJar (jarpaths , jarbase );
5154 addPath (cl , jar );
5255 }
5356
5457 public static void addJarToURLClassLoader (
55- URLClassLoader cl , String jarpath , String jarbase , String representativeClass
58+ URLClassLoader cl , String [] jarpaths , String jarbase , String representativeClass
5659 ) throws Exception {
5760 try {
5861 Class .forName (representativeClass , true , cl );
5962 } catch (ClassNotFoundException e ) {
6063 System .out .println ("[Scalive] Load " + jarbase );
61- Classpath .findAndAddJar (cl , jarpath , jarbase );
64+ Classpath .findAndAddJar (cl , jarpaths , jarbase );
6265 }
6366 }
6467
6568 // http://stackoverflow.com/questions/4121567/embedded-scala-repl-inherits-parent-classpath
6669 public static String getURLClasspath (URLClassLoader cl ) {
6770 URL [] urls = cl .getURLs ();
68- StringBuffer buf = new StringBuffer ();
69- for (URL url : urls ) {
70- if (buf .length () > 0 ) buf .append (File .pathSeparator );
71- buf .append (url );
72- }
73- return buf .toString ();
71+ return join (urls , File .pathSeparator );
7472 }
7573
7674 public static String getScalaVersion (ClassLoader cl ) throws Exception {
7775 Class <?> k = Class .forName ("scala.util.Properties" , true , cl );
7876 Method m = k .getDeclaredMethod ("versionNumberString" );
7977 return (String ) m .invoke (k );
8078 }
79+
80+ private static String join (Object [] xs , String separator ) {
81+ StringBuffer buf = new StringBuffer ();
82+ for (Object x : xs ) {
83+ if (buf .length () > 0 ) buf .append (separator );
84+ buf .append (x );
85+ }
86+ return buf .toString ();
87+ }
8188}
0 commit comments