David D. Lucas
Thu, 21 Apr 2005 05:21:52 -0700
I use this for debugging web environments.
Let me know if you have any questions.
Best Wishes, Dave
I will pass this on. However, what seems real strange is they cannot find dom4j in any of the jar files used in their system.
Is there a program somewhere which can walk the list of all jars loaded and see all locations of a given class? I'm guessing this would be hard to do in an application server as it does not use the classpath.
??? - thanks - dave
--
+------------------------------------------------------------+ | David Lucas mailto: ddlucas @ lse.com | | Lucas Software Engineering, Inc. (740) 964-6248 Voice | | Unix,Java,C++,CORBA,XML,EJB (614) 668-4020 Mobile | | Middleware,Frameworks (888) 866-4728 Fax/Msg | +------------------------------------------------------------+ | GPS Location: 40.0150 deg Lat, -82.6378 deg Long | | IMHC: "Jesus Christ is the way, the truth, and the life." | | IMHC: "I know where I am; I know where I'm going." <>< | +------------------------------------------------------------+
Notes: PGP Key Block=http://www.lse.com/~ddlucas/pgpblock.txt IMHO="in my humble opinion" IMHC="in my humble conviction" All trademarks above are those of their respective owners.
<%@ page import="java.net.URL,
java.util.Properties,
java.io.InputStream"
%>
<%@ page contentType="text/html;charset=iso-8859-1"%>
<jsp:useBean id='retrieveParms' class='java.util.HashMap' scope='session'/>
<%
int columns=60;
String checkClassName=(String)retrieveParms.get("className");
String checkClassLocation=(String)retrieveParms.get("classLocation");
if (checkClassName==null) {
checkClassName="";
retrieveParms.put("className",checkClassName);
}
if (checkClassLocation==null || checkClassName.length()==0) {
checkClassLocation="";
retrieveParms.put("classLocation",checkClassLocation);
}
String checkPropertyName=(String)retrieveParms.get("propertyName");
String checkPropertyFile=(String)retrieveParms.get("propertyFile");
String checkPropertyValue=(String)retrieveParms.get("propertyValue");
if (checkPropertyName==null) {
checkPropertyName="";
retrieveParms.put("propertyName",checkPropertyName);
}
if (checkPropertyFile==null) {
checkPropertyFile="";
retrieveParms.put("propertyFile",checkPropertyFile);
}
if (checkPropertyValue==null|| checkPropertyName.length()==0) {
checkPropertyValue="";
retrieveParms.put("propertyValue",checkPropertyValue);
}
%>
<html>
<head>
<title>
Check Class Location
</title>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
</head>
<body>
<FORM NAME="Class" ACTION="<%=response.encodeURL("CheckClass.jsp")%>"
METHOD="post">
<P>Enter fully qualified class to look up.</P>
<TABLE>
<TR VALIGN=TOP ALIGN=LEFT>
<TD><B><I>Class Name:</I></B></TD>
<TD><INPUT TYPE="text" SIZE="<%=columns%>" MAXLENGTH="256" NAME="ClassName"
VALUE='<%=
(String)retrieveParms.get("className")
%>' /><BR></TD>
</TR>
<TR VALIGN=TOP ALIGN=LEFT>
<TD><B><I>Location:</I></B></TD>
<TD><TEXTAREA TYPE="textarea" ROWS="10" COLS="<%=columns%>"
NAME="ClassLocation" READONLY="true" >
<%=(String)retrieveParms.get("classLocation")%>
</TEXTAREA><BR></TD>
</TR>
<TR VALIGN=TOP ALIGN=CENTER>
<TD><INPUT TYPE="SUBMIT" NAME="CheckClass" VALUE="CheckClass" /></TD>
</TR>
</TABLE>
</FORM>
<br/>
<HR/>
<br/>
<P>Enter property name ( and property file if loaded from classpath) to get
value.</P>
<FORM>
<TABLE>
<TR VALIGN=TOP ALIGN=LEFT>
<TD><B><I>Property Name:</I></B></TD>
<TD><INPUT TYPE="text" SIZE="<%=columns%>" MAXLENGTH="256" NAME="PropertyName"
VALUE='<%=
(String)retrieveParms.get("propertyName")
%>' /><BR></TD>
</TR>
<TR VALIGN=TOP ALIGN=LEFT>
<TD><B><I>Property File:</I></B></TD>
<TD><INPUT TYPE="text" SIZE="<%=columns%>" MAXLENGTH="256" NAME="PropertyFile"
VALUE='<%=
(String)retrieveParms.get("propertyFile")
%>' /><BR></TD>
</TR>
<TR VALIGN=TOP ALIGN=LEFT>
<TD><B><I>Value:</I></B></TD>
<TD><TEXTAREA TYPE="textarea" ROWS="2" COLS="<%=columns%>" NAME="PropertyValue"
READONLY="true" >
<%=(String)retrieveParms.get("propertyValue")%>
</TEXTAREA><BR></TD>
</TR>
<TR VALIGN=TOP ALIGN=CENTER>
<TD><INPUT TYPE="SUBMIT" NAME="GetProperty" VALUE="GetProperty" /></TD>
</TR>
</TABLE>
</FORM>
<HR/>
<%
int rc=200;
String redirect=null;
String submit=request.getParameter("CheckClass");
if (submit==null) submit=request.getParameter("GetProperty");
if (submit==null) submit="";
if ( "CheckClass".equals(submit)) {
String className = request.getParameter("ClassName");
String classLocation = request.getParameter("ClassLocation");
out.println("<br/><p>Checking for class "+className+" ...</p>");
retrieveParms.put("className",className);
retrieveParms.put("classLocation","");
try{
String search;
if (className.indexOf(".properties")==-1) {
search ="/"+className.replace('.','/')+".class";
}
else {
search=className;
}
URL url;
url = search.getClass().getResource(search);
if (url==null) {
url=Thread.currentThread().getContextClassLoader().getResource(search);
}
if (url==null) {
Class c;
try {
c =
Thread.currentThread().getContextClassLoader().loadClass(className);
url = c.getResource(search);
}
catch(Exception ignore) {}
}
if (url==null) {
ClassLoader
cl=Thread.currentThread().getContextClassLoader().getParent();
if (cl!=null) {
url = cl.getResource(search);
}
}
out.println("<br/><p>found under "+url+" ...</p>");
if (url!=null) {
classLocation=url.getPath();
}
else {
classLocation="NOT FOUND
!\n\nclasspath=\n"+System.getProperty("java.class.path")+
"\n\nbootclasspath=\n"+System.getProperty("sun.boot.class.path");
String pathSeparator=System.getProperty("path.separator");
classLocation=classLocation+"\n\nenv=\n"+System.getProperties().toString().replace(',','\n');
classLocation=classLocation.replaceAll(pathSeparator,pathSeparator+"\n") ;
}
retrieveParms.put("classLocation",classLocation);
//now clear bottom by refresh
redirect=response.encodeRedirectURL("CheckClass.jsp");
}
catch(Exception e) {
rc=500;
e.printStackTrace();
out.println("<br/>Error trying to find class:
"+e.getMessage()+"<br/>");
out.println("<br/>"+e+"<br/>");
}
}
else if ("GetProperty".equals(submit)) {
try{
String propertyName = request.getParameter("PropertyName");
String propertyFile = request.getParameter("PropertyFile");
String propertyValue = request.getParameter("PropertyValue");
out.println("<br/><p>Checking for property "+propertyName+" ...</p>");
retrieveParms.put("propertyFile",propertyFile);
retrieveParms.put("propertyValue","");
retrieveParms.put("propertyName",propertyName);
propertyValue=null;
Properties props=System.getProperties();
if (propertyFile.length()>0) {
String search="/"+propertyFile;
URL url;
url = search.getClass().getResource(search);
if (url==null) {
url=Thread.currentThread().getContextClassLoader().getResource(search);
}
if (url==null) {
ClassLoader
cl=Thread.currentThread().getContextClassLoader().getParent();
if (cl!=null) {
url = cl.getResource(search);
}
}
out.println("<br/><p>found under "+url+" ...</p>");
if (url!=null) {
props=new Properties();
InputStream is=null;
String error=null;
try {
props.clear();
is = url.openStream();
props.load(is);
}
catch(Exception e){
error=""+e;
out.println("<br/><p>"+error+"</p><br/>");
propertyValue=" ### ERROR loading property file
"+propertyFile+" from classpath!\n"+error;
}
finally{
if (is!=null) {
is.close();
}
}
}
}
//find the value
if (propertyValue==null) {
propertyValue=props.getProperty(propertyName);
if (propertyValue==null) {
propertyValue=" ### no property defined ";
}
}
out.println("<br/><p>propertyValue="+propertyValue+"</p><br/>");
out.println("<br/><p>requestParms="+retrieveParms+"</p><br/>");
retrieveParms.put("propertyValue",propertyValue);
//now clear bottom by refresh
redirect=response.encodeRedirectURL("CheckClass.jsp");
}
catch(Exception e) {
rc=500;
e.printStackTrace();
out.println("<br/>Error trying to find class:
"+e.getMessage()+"<br/>");
out.println("<br/>"+e+"<br/>");
}
}
response.setStatus(rc);
if (redirect!=null) {
response.sendRedirect(redirect);
}
%>
<br/>
<p/><p/>
This simple utility provided AS IS from <a href="http://www.lse.com">Lucas
Software Engineering, Inc.</a>, Copyright 2005<br/>
No WARRANTIES, expressed or implied.<br/>
</body>
</html>