直接上干货:
/**
* @see ServletContextListener#contextInitialized(ServletContextEvent)
*/
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println("context over");
System.out.println(MyListern.class.getResource(""));
System.out.println(MyListern.class.getResource("/aj.properties"));
new com.bjp2.MyResourceUtil().get();
new MyResourceUtil().get();
package com.bjp;
public class MyResourceUtil {
public void get() {
System.out.println("****************************");
System.out.println(MyResourceUtil.class.getResource(""));
System.out.println(MyResourceUtil.class.getResource("/aj.properties"));
}
}
package com.bjp2;
public class MyResourceUtil {
public void get() {
System.out.println("****************************");
System.out.println(MyResourceUtil.class.getResource(""));
System.out.println(MyResourceUtil.class.getResource("/aj.properties"));
}
}
context over
file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/classes/com/lwx/
jar:file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/lib/bjp.jar!/aj.properties
****************************
jar:file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/lib/bjp2.jar!/com/bjp2/
jar:file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/lib/bjp.jar!/aj.properties
****************************
jar:file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/lib/bjp.jar!/com/bjp/
jar:file:/D:/tomcat7/apache-tomcat-7.0.85/wtpwebapps/usm/WEB-INF/lib/bjp.jar!/aj.properties
三月 08, 2018 12:06:17 上午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/usm] is completed