编写srcAdd.jsp,然后拷贝到web应用的根目录下面,通过以下方式即可查看JVM是从那个类包加载指定类:
localhost:9090/srcAdd.jsp?className=java.net.URL
srcAdd.jsp内容:
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="java.security.*,java.net.*,java.io.*"%>
<%!
public static URL getClassLocation(final Class cls) {
if (cls == null)throw new IllegalArgumentException("null input: cls");
URL result = null;
final String clsAsResource = cls.getName().replace('.', '/').concat(".class");
final ProtectionDomain pd = cls.getProtectionDomain();
// java.lang.Class contract does not specify if 'pd' can ever be null;
// it is not the case for Sun's implementations, but guard against null
// just in case:
if (pd != null) {
final CodeSource cs = pd.getCodeSource();
// 'cs' can be null depending on the classloader behavior:
if (cs != null) result = cs.getLocation();
if (result != null) {
// Convert a code source location into a full class file location
// for some common cases:
if ("file".equals(result.getProtocol())) {
try {
if (result.toExternalForm().endsWith(".jar") ||
result.toExternalForm().endsWith(".zip"))
result = new URL("jar:".concat(result.toExternalForm())
.concat("!/").concat(clsAsResource));
else if (new File(result.getFile()).isDirectory())
result = new URL(result, clsAsResource);
}
catch (MalformedURLException ignore) {}
}
}
}
if (result == null) {
// Try to find 'cls' definition as a resource; this is not
// document.d to be legal, but Sun's implementations seem to //allow this:
final ClassLoader clsLoader = cls.getClassLoader();
result = clsLoader != null ?
clsLoader.getResource(clsAsResource) :
ClassLoader.getSystemResource(clsAsResource);
}
return result;
}
%>
<html>
<head>
<title>srcAdd.jar</title>
</head>
<body bgcolor="#ffffff">
使用方法,className对应的值为类的全名,不需要.class后缀,如下面则是查询加载类java.net.URL的jar包
srcAdd.jsp?className=java.net.URL
<%
try
{
String classLocation = null;
String error = null;
String className = request.getParameter("className");
classLocation = ""+getClassLocation(Class.forName(className));
if (error == null) {
out.print("类" + className + "实例的物理文件位于:");
out.print("<hr>");
out.print(classLocation);
}
else {
out.print("类" + className + "没有对应的物理文件。<br>");
out.print("错误:" + error);
}
}catch(Exception e)
{
out.print("异常。"+e.getMessage());
}
%>
</body>
</html>
相关推荐
java连接oracle数据库jar包
关于执行java命令引入外部jar包方法
java数据库驱动 SQL Server 2005 的 和JDTS 的
在jdk1.2以后,类加载是通过委托来完成的,这意味着如果 ClassLoader 不能找到类,它会请求父代 ClassLoader 来执行此项任务,所有 ClassLoaders 的根是系统 ClassLoader,它会以缺省方式装入类 -- 即,从本地文件...
NULL 博文链接:https://genius.iteye.com/blog/296000
java Excel和Word导出需要添加的jar包,直接导入即可用
Java 自动加载JAR文件并运行其中的类方法
java操作excel的jar包,包括三个jar包,java加载这三个jar包即可实现对excel的创建,读取,写入数据等操作。
jxl.jar概述: 通过java操作excel表格的工具类库 ...如果包不能正常的加载,可以把你下载好的JXL.JAR包放入D:\JAVA\jre\lib\ext中(我的是JDK1.6)就OK了。我相信在配置TOMCAT时也需要把相关的三个包放到这里面。
Java web 项目中所需要的常用jar包 很全面 是有一天做项目时发现缺少很多jar包 寻找这些jar包几乎花了我一下午的时间 为方便后来人 故寻找下载并整理了一些jar包 希望对读者有所帮助 因为下载包时消耗了我大量积分 ...
支持servlet的jar包。应该叫servlet-api.jar 你如果编写过servlet就...如果你安装了Tomcat,这个jar包一般在tomcat安装目录\lib 文件夹下面有,当你把web项目部署到tomcat,会自动加载这个jar包来识别Serlvet一些对象。
springboot 、java类热加载、jarinjar、动态编译、自动引用依赖
代码生成工具 Hibernate用它在运行时扩展 Java类和实现,同cglib包 slf4j-api-1.5.8.jar和slf4j-log4j12-1.5.0.jar hibernate使用的一个日志系统 spring.jar spring核心包 spring-security-core-2.0.4.jar 和 ...
该类加载器用于从指向 JAR 文件和目录的 URL 的搜索路径加载类和资源。如果不是以该字符结束,则认为该 URL 指向一个将根据需要打开的 JAR 文件pac
JAVA动态加载JAR,zip包例子 有在项目中用到
XXXX.jar为JAVA打包好的jar包文件。 ikvmc [ options ] classOrJarfile [ classOrJarfile ... ] C#使用时以下文件必须 %IKVM_HOME%\bin\IKVM.OpenJDK.Core.dll %IKVM_HOME%\bin\IKVM.Runtime.dll %IKVM_...
ImGui的JAVA版本JImGui的jar包,下载之后直接添加使用即可
zip压缩以及解压工具类,本人纯手打。其中包括zip所需要的jar 文件,copy到项目中可直接运行,以及工具类添加注释
通过动态加载jar包的方式,反射调用内部方法