Methods Summary |
---|
public static java.lang.String | expandDirs(java.lang.String dirPaths)Expand a directory path or list of directory paths (File.pathSeparator
delimited) into a list of file paths of all the jar files in those
directories.
StringTokenizer st = new StringTokenizer(dirPaths, File.pathSeparator);
StringBuffer buffer = new StringBuffer();
while (st.hasMoreTokens()) {
String d = st.nextToken();
File dir = new File(d);
if (dir.isDirectory()) {
File[] files = dir.listFiles(new JavaArchiveFilter());
for (int i = 0; i < files.length; i++) {
buffer.append(files[i]).append(File.pathSeparator);
}
}
}
return buffer.toString();
|
private static void | fillClassPath(java.lang.ClassLoader cl, java.lang.StringBuffer classpath)Walk the classloader hierarchy and add to the classpath
while (cl != null) {
if (cl instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) cl).getURLs();
for (int i = 0; (urls != null) && i < urls.length; i++) {
String path = urls[i].getPath();
//If it is a drive letter, adjust accordingly.
if (path.length() >= 3 && path.charAt(0) == '/" && path.charAt(2) == ':")
path = path.substring(1);
classpath.append(URLDecoder.decode(path));
classpath.append(File.pathSeparatorChar);
// if its a jar extract Class-Path entries from manifest
File file = new File(urls[i].getFile());
if (file.isFile()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
if (isJar(fis)) {
JarFile jar = new JarFile(file);
Manifest manifest = jar.getManifest();
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
if (attributes != null) {
String s = attributes.getValue(Attributes.Name.CLASS_PATH);
String base = file.getParent();
if (s != null) {
StringTokenizer st = new StringTokenizer(s, " ");
while (st.hasMoreTokens()) {
String t = st.nextToken();
classpath.append(base + File.separatorChar + t);
classpath.append(File.pathSeparatorChar);
}
}
}
}
}
} catch (IOException ioe) {
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ioe2) {
}
}
}
}
}
}
cl = cl.getParent();
}
|
private static void | getClassPathFromDirectoryProperty(java.lang.StringBuffer classpath, java.lang.String property)Add all files in the specified directory to the classpath
String dirs = AxisProperties.getProperty(property);
String path = null;
try {
path = ClasspathUtils.expandDirs(dirs);
} catch (Exception e) {
// Oh well. No big deal.
}
if (path != null) {
classpath.append(path);
classpath.append(File.pathSeparatorChar);
}
|
private static void | getClassPathFromProperty(java.lang.StringBuffer classpath, java.lang.String property)Add a classpath stored in a property.
String path = AxisProperties.getProperty(property);
if (path != null) {
classpath.append(path);
classpath.append(File.pathSeparatorChar);
}
|
public static java.lang.String | getDefaultClasspath(org.apache.axis.MessageContext msgContext)Get the default classpath from various thingies in the message context
StringBuffer classpath = new StringBuffer();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
fillClassPath(cl, classpath);
// Just to be safe (the above doesn't seem to return the webapp
// classpath in all cases), manually do this:
String webBase = (String) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION);
if (webBase != null) {
classpath.append(webBase + File.separatorChar + "classes" +
File.pathSeparatorChar);
try {
String libBase = webBase + File.separatorChar + "lib";
File libDir = new File(libBase);
String[] jarFiles = libDir.list();
for (int i = 0; i < jarFiles.length; i++) {
String jarFile = jarFiles[i];
if (jarFile.endsWith(".jar")) {
classpath.append(libBase +
File.separatorChar +
jarFile +
File.pathSeparatorChar);
}
}
} catch (Exception e) {
// Oh well. No big deal.
}
}
// axis.ext.dirs can be used in any appserver
getClassPathFromDirectoryProperty(classpath, "axis.ext.dirs");
// classpath used by Jasper
getClassPathFromProperty(classpath, "org.apache.catalina.jsp_classpath");
// websphere stuff.
getClassPathFromProperty(classpath, "ws.ext.dirs");
getClassPathFromProperty(classpath, "com.ibm.websphere.servlet.application.classpath");
// java class path
getClassPathFromProperty(classpath, "java.class.path");
// Load jars from java external directory
getClassPathFromDirectoryProperty(classpath, "java.ext.dirs");
// boot classpath isn't found in above search
getClassPathFromProperty(classpath, "sun.boot.class.path");
return classpath.toString();
|
public static boolean | isJar(java.io.InputStream is)Check if this inputstream is a jar/zip
try {
JarInputStream jis = new JarInputStream(is);
if (jis.getNextEntry() != null) {
return true;
}
} catch (IOException ioe) {
}
return false;
|