001: /*
002: * Created on Mar 14, 2004
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package com.pk;
008:
009: import java.io.File;
010: import java.io.FilenameFilter;
011: import java.net.URL;
012: import java.net.URLClassLoader;
013:
014: /**
015: * @author Isabelle
016: *
017: * To change the template for this generated type comment go to
018: * Window>Preferences>Java>Code Generation>Code and Comments
019: */
020: public class StartUpLoader {
021: private static URLClassLoader loader;
022: static {
023: // File libDir = new File("./lib/");
024: // File currLib = new File("./");
025: // StringBuffer classpath = new StringBuffer();
026: // try
027: // {
028: // String classPathSeparator = System.getProperty("path.separator");
029: // File[] libJars = libDir.listFiles(new FilenameFilter()
030: // {
031: // public boolean accept(File dir, String name)
032: // {
033: // boolean acceptFile = false;
034: // if (name.endsWith(".jar") || name.endsWith(".zip"))
035: // {
036: // acceptFile = true;
037: // }
038: // return acceptFile;
039: // }
040: // });
041: // URL tmp[] = new URL[libJars.length + 1];
042: // String origPath = null;
043: // boolean usesUNC = System.getProperty("os.name").startsWith("Windows");
044: // for (int i = 0; i < libJars.length + 1; i++)
045: // {
046: // if (i < libJars.length)
047: // {
048: // origPath = libJars[i].getCanonicalPath();
049: // }
050: // else
051: // {
052: // origPath = currLib.getCanonicalPath();
053: // }
054: //
055: // // allow UNC URLs
056: // if (usesUNC)
057: // {
058: // if (origPath.startsWith("\\\\") && !origPath.startsWith("\\\\\\"))
059: // {
060: // origPath = "\\\\" + origPath;
061: // }
062: // else if (origPath.startsWith("//") && !origPath.startsWith("///"))
063: // {
064: // origPath = "//" + origPath;
065: // }
066: // }
067: // tmp[i] = new URL("file:/" + origPath);
068: // classpath.append(origPath);
069: // }
070: // tmp[tmp.length - 1] = new URL("file:/" + origPath + "/");
071: // System.setProperty("java.class.path", System.getProperty("java.class.path") + classPathSeparator + classpath.toString());
072: // loader = new URLClassLoader(tmp, null);
073: //
074: // }
075: // catch (Exception e)
076: // {
077: // e.printStackTrace();
078: // }
079:
080: }
081:
082: public static void main(String[] args) {
083: File libDir = new File("./lib/");
084: File currLib = new File("./");
085: StringBuffer classpath = new StringBuffer();
086: try {
087: String classPathSeparator = System
088: .getProperty("path.separator");
089: File[] libJars = libDir.listFiles(new FilenameFilter() {
090: public boolean accept(File dir, String name) {
091: boolean acceptFile = false;
092: if (name.endsWith(".jar") || name.endsWith(".zip")) {
093: acceptFile = true;
094: }
095: return acceptFile;
096: }
097: });
098: URL tmp[] = new URL[libJars.length + 1];
099: String origPath = null;
100: boolean usesUNC = System.getProperty("os.name").startsWith(
101: "Windows");
102: for (int i = 0; i < libJars.length + 1; i++) {
103:
104: if (i < libJars.length) {
105: origPath = libJars[i].getAbsolutePath();
106: } else {
107: origPath = currLib.getAbsolutePath();
108: }
109: // allow UNC URLs
110:
111: if (usesUNC) {
112: if (origPath.startsWith("\\\\")
113: && !origPath.startsWith("\\\\\\")) {
114: origPath = "\\\\" + origPath;
115: } else if (origPath.startsWith("//")
116: && !origPath.startsWith("///")) {
117: origPath = "//" + origPath;
118: }
119: }
120: tmp[i] = new URL("file:" + origPath);
121: classpath.append(origPath);
122: }
123: tmp[tmp.length - 1] = new URL("file:/" + origPath + "/");
124: System.setProperty("java.class.path", System
125: .getProperty("java.class.path")
126: + classPathSeparator + classpath.toString());
127: loader = new URLClassLoader(tmp, null);
128: } catch (Exception e) {
129: e.printStackTrace();
130: }
131:
132: Thread.currentThread().setContextClassLoader(loader);
133: Class tmp2;
134: try {
135: tmp2 = loader.loadClass("com.pk.PrettyKid");
136: tmp2.newInstance();
137: } catch (Exception e) {
138: e.printStackTrace();
139: }
140: }
141: }
|