At 03:00 PM 7/26/2001 -0500, Rich Catlett wrote:
>I tried running the cp.jsp but I get a servlet exception with the root cause being
>this
>
>java.lang.ExceptionInInitializerError: java.lang.ClassCastException:
>....
>I went into the jsp and edited it ... ... ... and then I got this error
>
>java.lang.NoClassDefFoundError
>Any suggestions!
Ouch. I'd written the calls within try{...}catch(Exception ex){out.write...}
blocks, expecting this to catch any exceptions---and it would have. Unfortunately,
java.lang.ExceptionInInitializerError and java.lang.NoClassDefFoundError do
_not_ extend Exception, they extend Throwable. So I've just editted the code to
replace those two Exceptions with Throwable; that should prevent collapse.
Thanks for trying it.
The implication appears to be that Xerces is just not being found, unless it
means that Xerces 1.4.2 has dropped the framework.Version.fVersion system..so I
just downloaded Xerces 1.4.2 (source) and looked, and am not surprised because
it's still there. My suspicion is that the classpath you tried to set up is not
the one you're getting, as happens all too often to people on this list.
Tom Myers
public class cp {
/* test classpath (and other system properties); if you improve this
code, please tell <a href="mailto:[EMAIL PROTECTED]">Tom Myers</a> about it,
unless you'd really rather not.
*/
public static void main(String[]args){
try{ // spaces between classpath entries for readability
System.out.println("CLASSPATH:");
String cp=System.getProperty("java.class.path");
java.util.StringTokenizer st=new java.util.StringTokenizer(cp,";");
while(st.hasMoreTokens())System.out.print(st.nextToken()+"; ");
}catch(Exception ex){System.out.print("can't get classpath, exception: "+ex);}
System.out.println();
System.out.println();
System.out.print("EXTENSIONS DIRS:");
try{
String edirs=System.getProperty("java.ext.dirs");
java.util.StringTokenizer st=new java.util.StringTokenizer(edirs,";");
while(st.hasMoreTokens()) { // I'm not sure there'll ever be more than 1
String ed=st.nextToken();
System.out.println();System.out.println(ed+":");
java.io.File edDir=new java.io.File(ed);
if(!edDir.exists())throw new Exception( "no such directory as "+ed);
if(!edDir.isDirectory())throw new Exception( ed + " is not a directory.");
String[] LL = edDir.list();
for(int i=0;i<LL.length;i++)System.out.print(i==0?LL[i]:"; "+LL[i]);
}
}catch(Exception ex){System.out.print("can't get extensions dir, exception: "+ex);}
System.out.println();System.out.println();
System.out.print("XERCES VERSION=");
try{
System.out.println(Class.forName("org.apache.xerces.framework.Version")
.getField("fVersion").get(null).toString());
// equiv to
// System.out.print(org.apache.xerces.framework.Version.fVersion);
// but compiles even in the absence of xerces.
}catch(Throwable ex){System.out.println("not found");}
System.out.println();
System.out.print("DOM DocumentBuilder class=");
try{ // similarly, we want to compile in the absence of Apache SOAP
//
System.out.print(org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder().getClass().getName());
System.out.println(Class.forName("org.apache.soap.util.xml.XMLParserUtils")
.getMethod("getXMLDocBuilder",new Class[]{})
.invoke(null,new Object[]{})
.getClass().getName() );
}catch(Throwable ex){System.out.println("not found");}
System.out.println();
System.out.println("MISCELLANEOUS PROPERTIES");
try{System.getProperties().store(System.out,"SysProps");}
catch(java.io.IOException ex){System.out.println("can't store system props to
System.out?");}
}
}
<html><head><title>Classpath and so forth</title></head>
<body>
Classpath (and other system properties); if you improve this
code, please tell <a href="mailto:[EMAIL PROTECTED]">Tom Myers</a> about it,
unless you'd really rather not.
<h4>Classpath:</h4>
<%
try{ // spaces between classpath entries for readability
String cp=System.getProperty("java.class.path");
java.util.StringTokenizer st=new java.util.StringTokenizer(cp,";");
while(st.hasMoreTokens())out.write(st.nextToken()+"; ");
}catch(Exception ex){out.write("can't get classpath, exception: "+ex);}
%>
<br>
<p>That is the classpath as seen by this specific JSP page, constructed by
the servlet-runner (Tomcat, JRun, whatever). If it's a surprise,
look in the setup (e.g., jakarta-tomcat/bin/tomcat.[bat,sh] or
jrun/lib/global.properties ) to see how
it's constructed. Servlet-runners often put their own classes in front,
and you may need to change that.
</p><p>
It is likely to be the classpath for your servlet/JSP/SOAP-service code,
but may not be if you're running an app in its own virtual machine;
for example, WebSphere applications are described at
<a href="http://service2.boulder.ibm.com/devtools/news0101/art36.htm">IBM</a>
as "In the WebSphere 3 administration console using the topology tab, navigate to your
Web application, for example, the default_app. On the advanced tab, specify the
classpath..."
So check your documentation, especially in any enterprise app situation.
</p>
<h4>Extensions dirs</h4>
<%
try{
String edirs=System.getProperty("java.ext.dirs");
java.util.StringTokenizer st=new java.util.StringTokenizer(edirs,";");
while(st.hasMoreTokens()) { // I'm not sure there'll ever be more than 1
String ed=st.nextToken();
out.write("<b>"+ed+":</b><br>");
java.io.File edDir=new java.io.File(ed);
if(!edDir.exists())throw new Exception( "no such directory as "+ed);
if(!edDir.isDirectory())throw new Exception( ed + " is not a directory.");
String[] LL = edDir.list();
for(int i=0;i<LL.length;i++)out.write(i==0?LL[i]:"; "+LL[i]);
}
}catch(Throwable ex){out.write("can't get extensions dir, exception: "+ex);}
%>
<p><b>Classes in extension-dir jars are read in <em>before</em> those on the
classpath</b>
(i.e., they are "in front of the classpath"), but they are read by the extension
classloader.
They are visible to those in classpath,
but those in classpath may not be visible to them. (You can look upwards in the
hierarchy
of classloaders, but not down.)
Similarly, the classes in your webapp's WEB-INF/classes and WEB-INF/lib/*.jar locations
will be loaded by the servlet-runner's classloader, which is below the system
classloader;
details vary.</p>
<h4>Xerces Version=
<%
try{
out.write(Class.forName("org.apache.xerces.framework.Version")
.getField("fVersion").get(null).toString());
// equiv to
// out.write(org.apache.xerces.framework.Version.fVersion);
// but compiles even in the absence of xerces.
}catch(Throwable ex){out.write("not found");}
%></h4>
<h4>SOAP's DOM DocumentBuilder class=
<%
try{ // similarly, we want to compile in the absence of Apache SOAP
//
out.write(org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder().getClass().getName());
out.write(Class.forName("org.apache.soap.util.xml.XMLParserUtils")
.getMethod("getXMLDocBuilder",new Class[]{})
.invoke(null,new Object[]{})
.getClass().getName() );
}catch(Throwable ex){out.write("not found");}
%></h4>
<h4>Miscellaneous properties:</h4>
<p>e.g., user.dir is where you look for files by default.</p>
<pre>
<%
final java.io.Writer w=out;
java.io.OutputStream os=new java.io.OutputStream(){
public void write(int b)throws java.io.IOException{w.write(b);}
};
System.getProperties().store(os,"SysProps");
%>
</pre>
</body>
</html>