首页 > 其他 > 详细

[简单]代码片段_2

时间:2014-11-18 02:10:29      阅读:245      评论:0      收藏:0      [点我收藏+]

?????

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);
		}
	}
}

??? 全文完

[简单]代码片段_2

原文:http://53873039oycg.iteye.com/blog/2157251

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!