标签:oracle 依赖库 ssl run art ref mave param html
import java.io.IOException; import java.net.URL; import java.net.URLDecoder; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.io.*; public class JarFinder { public static void FindClassInJar(String jarName) throws IOException { String filePath = jarName; if (filePath.endsWith(".jar")) { } else return; java.util.jar.JarFile file = new JarFile(filePath); Enumeration<JarEntry> entrys = file.entries(); while (entrys.hasMoreElements()) { JarEntry jar = entrys.nextElement(); String tmpJarName = jar.getName(); tmpJarName = tmpJarName.replace(‘/‘, ‘.‘); if (tmpJarName.contains("javax.mail.Multipart")) { System.out.println(tmpJarName + " " + file.getName()); } } file.close(); } final static void ShowAllFileInDir(File dir) throws Exception { File[] fs = dir.listFiles(); for (int i = 0; i < fs.length; i++) { String file = fs[i].getAbsolutePath(); FindClassInJar(file); if (fs[i].isDirectory()) { try { ShowAllFileInDir(fs[i]); } catch (Exception e) { } } } } public static void main(String[] args) throws Exception { File root = new File("C:/Program Files/Java/jdk1.8.0_102/jre/lib/ext"); ShowAllFileInDir(root); } }
public static String getProjectPath() { java.net.URL url = oracle.sql.NCLOB.class.getProtectionDomain().getCodeSource().getLocation(); String filePath = null; try { filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } if (filePath.endsWith(".jar")) filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1); java.io.File file = new java.io.File(filePath); filePath = file.getPath(); return filePath; } public static String getRealPath() { String realPath = oracle.sql.NCLOB.class.getClassLoader().getResource("").getFile(); //java.io.File file = new java.io.File(realPath); //realPath = file.(); System.out.println(realPath); try { realPath = java.net.URLDecoder.decode(realPath, "utf-8"); } catch (Exception e) { e.printStackTrace(); } return realPath; } public static String getAppPath(Class<?> cls) { // 检查用户传入的参数是否为空 if (cls == null) throw new java.lang.IllegalArgumentException("参数不能为空!"); ClassLoader loader = cls.getClassLoader(); // 获得类的全名,包括包名 String clsName = cls.getName(); // 此处简单判定是否是Java基础类库,防止用户传入JDK内置的类库 if (clsName.startsWith("java.") || clsName.startsWith("javax.")) { throw new java.lang.IllegalArgumentException("不要传送系统类!"); } // 将类的class文件全名改为路径形式 String clsPath = clsName.replace(".", "/") + ".class"; System.out.println(clsPath); // 调用ClassLoader的getResource方法,传入包含路径信息的类文件名 java.net.URL url = loader.getResource(clsPath); // 从URL对象中获取路径信息 String realPath = url.getPath(); System.out.println(realPath); // 去掉路径信息中的协议名"file:" int pos = realPath.indexOf("file:"); if (pos > -1) { realPath = realPath.substring(pos + 5); } //System.out.println(realPath); // 去掉路径信息最后包含类文件信息的部分,得到类所在的路径 //pos = realPath.indexOf(clsPath); //realPath = realPath.substring(0, pos - 1); // 如果类文件被打包到JAR等文件中时,去掉对应的JAR等打包文件名 //if (realPath.endsWith("!")) { // realPath = realPath.substring(0, realPath.lastIndexOf("/")); //} //java.io.File file = new java.io.File(realPath); //realPath = file.getAbsolutePath(); try { realPath = java.net.URLDecoder.decode(realPath, "utf-8"); } catch (Exception e) { throw new RuntimeException(e); } return realPath; }
标签:oracle 依赖库 ssl run art ref mave param html
原文地址:http://www.cnblogs.com/wangn/p/6072518.html