Find all jar files in a directory
All jar files in a directory:
import java.io.File;
import java.io.FilenameFilter;
public class AllFilesInDir {
public static void main(String[] args) {
String cp = getClasspath("c:/temp/WEB-INF/lib");
System.out.println("cp=" + cp);
}
private static String getClasspath (String jarlib) {
String cp = "";
File dir = new File(jarlib);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
};
String[] children = dir.list(filter);
if (children == null) {
return cp;
}
String os = System.getProperty("os.name");
int pos = os.indexOf("400");
String deli = pos < 0 ? ";" : ":";
for (int i=0; i<children.length; i++) {
String f = children[i];
cp += f + deli;
//System.out.println("file=" + f);
}
return cp;
}
}
0 Comments:
Post a Comment
<< Home