[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ClassLoader problem in Servlet environment (Tomcat)
Unfortunately, this didn't fix the problem.
I still get this exception:
org.ozoneDB.ClassNotFoundExc: com.javawebguy.smg.db.ozone.NewsImpl
at org.ozoneDB.ExternalDatabase.sendCommand(ExternalDatabase.java:508)
at org.ozoneDB.ExternalDatabase.sendCommand(ExternalDatabase.java:476)
at org.ozoneDB.ExternalDatabase.createObject(ExternalDatabase.java:708)
at org.ozoneDB.ExternalDatabase.createObject(ExternalDatabase.java:702)
at
com.javawebguy.smg.actions.OzoneNewsAction.perform(OzoneNewsAction.java:99)
at
org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1620)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1430)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:464)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
So, I assumed that the Thread's ContextClassLoader doesnt' work either. To test
this, I used the folloeing code:
LocalDatabase db = new LocalDatabase();
db.open("/tmp/ozoneDB", 3);
System.out.println( "Connected ..." );
db.reloadClasses();
try {
System.out.println("Testing `this` class loader...");
News foo = (News) this.getClass()
.getClassLoader()
.loadClass(NewsImpl.class.getName())
.newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace(System.out);
}
try {
System.out.println("Testing Thread class loader...");
News bar = (News) Thread.currentThread()
.getContextClassLoader()
.loadClass(NewsImpl.class.getName())
.newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace(System.out);
}
And received the following as a result:
Testing `this` class loader...
Testing Thread class loader...
java.lang.ClassNotFoundException: com.javawebguy.smg.db.ozone.NewsImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at
com.javawebguy.smg.actions.OzoneNewsAction.perform(OzoneNewsAction.java:110)
It seems that using the servlet's ClassLoader would work. Or, better yet, setting
the servler's ClassLoader as the parent of the OzoneClassLoader, so that when the
OzoneClassLoader delegates up the chain, the required resources are found. So, I
propose that LocalDatabase be modified to accept a ClassLoader in it's constructor
so that users may optionally choose to specify the parent ClassLoader for the ozone
Env.
Falko, what do you think? I've started hacking at this solution, but have had no
luck yet. Do you know where changes would need to be made to support this
behavior?
Thanks,
Nathan Probst
Falko Braeutigam wrote:
> On Fri, 09 Mar 2001, Falko Braeutigam wrote:
> > On Fri, 09 Mar 2001, Nathan Eric Probst wrote:
> :
> > > I can make it work with RemoteDatabase by putting my WEB-INF/classes
> > > directory in the classpath when I start ozone, but this is not a good
> > > solution.
> >
> > There are two ClassLoaders in ozone, one for jdk1.1 and one for jdk1.2+. By
> > default the 1.1 is used. This one calls Class.forName() to actually get the
> > class. I'm not sure if Class.forName() uses the threads ClassLoader which is
> > needed to get the servlet ClassLoader which probably has access to the WEB-INF
> > classes. I will check this. Stay tuned.
>
> I've committed a small patch. ClassManager now uses context loader directly
> instead of the ozone loader. Thus the ozone server should now have access to
> all the classes that the servlet engine wants to make available to your servlet
> (WEB-INF/classes).
>
> Falko
>
> >
> >
> > Falko
> >
> > >
> > > In fact, I need to be able to use only a LocalDatabase and no special
> > > classpath treatments. The app I'm developing will be deployed to a
> > > third-party hosting provider where I will not have control over the
> > > environment. So, everything need to work from within the servlet
> > > context.
> > >
> > > Please help!
> > >
> > > Thanks,
> > > Nathan Probst
> > --
> > ______________________________________________________________________
> > Falko Braeutigam mailto:falko@smb-tec.com
> > SMB GmbH http://www.smb-tec.com
> --
> ______________________________________________________________________
> Falko Braeutigam mailto:falko@smb-tec.com
> SMB GmbH http://www.smb-tec.com