// 第一种:获取类加载的根路径
//返回的路径:E:\Tomcat\apache-tomcat-6.0.35\webapps\xasj\WEB-INF\classes
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
//第二种 获取当前文件所在的包目录
/*E:\Tomcat\apache-tomcat-6.0.35\webapps\xasj\WEB-INF\classes\com\jeecms\cms\action\directive*/
File f2 = new File(this.getClass().getResource("").getPath());
System.out.println(f2);
1. 配置文件的加载
//获取 配置文件 jdbc.properties的jdbc.url字段的值
String path = getClass().getClassLoader().getResource("/").getPath();+"../config/jdbc.properties";
Properties p = new Properties();
InputStream in = new FileInputStream(path);
p.load(in);
String url = p.getProperty("jdbc.url");