com.wenjx.aboutClass.LoadingFromWhere is loaded from file:/E:/LoadingFromWhere.jar com.wenjx.aboutClass.MyClass is loaded from file:/E:/LoadingFromWhere.jar
再看下面一段代码:
FromWhere.javapackage com.wenjx.aboutClass;
publicclass FromWhere {
publicstaticvoid main(String args[]){
Class theClass = FromWhere.class;
java.net.URL u = theClass.getResource("");
System.out.println("This class (FromWhere) is located at : " + u);
}
}
程序输出为: This class (FromWhere) is located at : file:/E:/work/General/bin/com/wenjx/aboutClass/
把上面的程序打成jar包然后在cmd中输入 java -jar FromWhere.jar,输出结果为: This class (FromWhere) is located at : jar:file:/E:/FromWhere.jar!/com/wenjx/aboutClass/