?????
import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; public class 打印Jar_S3_Test { public static void main(String[] args) { 打印Jar_S3_Test t = new 打印Jar_S3_Test(); t.getProjectsAllJarsFullPath(); System.out.println("----------------------------"); List<String> jarList = t.getProjectsAllJars(); for (String sub : jarList) { System.out.println(sub); } } /** * @Description: 打印jar名称 * @see: http://www.mkyong.com/java/how-to-print-out-the-current-project- * classpath/ */ public void getProjectsAllJarsFullPath() { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) cl).getURLs(); for (URL url : urls) { System.out.println(url.getFile()); } } /** * @Description: 打印jar名称 * @see: http://www.mkyong.com/java/how-to-print-out-the-current-project- * classpath/ */ public List<String> getProjectsAllJars() { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) cl).getURLs(); List<String> jarList = new ArrayList<String>(); for (URL url : urls) { if (!StringUtils.isBlank(getJarName(url.getFile()))) { jarList.add(getJarName(url.getFile())); } } return jarList; } public String getJarName(String path) { path = path.replace("\\", "/"); path = path.replace("/", File.separator); if (path.lastIndexOf(File.separator) == -1) { return path; } else { return path.substring(path.lastIndexOf(File.separator) + 1); } } }
??? 全文完。
原文:http://53873039oycg.iteye.com/blog/2157251