You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jonathan Yom-Tov <jo...@sysaid.com> on 2020/05/12 17:38:29 UTC

ClassNotFoundException when loading session from disk

I'm trying to use PersistentManager with FileStore to load sessions from
disk. Serialization goes ok but when the session is loaded I get an
exception deserializing one of my application's classes.

[2020-05-12 09:08:52] [SEVERE] Session:
6325A48BA1D2FC79105C7F4B0A76CB74.worker1;
java.lang.ClassNotFoundException: com.mycompany.MyClass
        at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
        at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at
org.apache.catalina.util.CustomObjectInputStream.resolveClass(CustomObjectInputStream.java:159)
        at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1620)
        at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
        at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
        at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
        at
org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1576)
        at
org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1048)
        at org.apache.catalina.session.FileStore.load(FileStore.java:234)

Looking into the classpath when the exception occurs I see that every jar
in ${catalina.base}/lib is loaded plus those explicitly mentioned in the
run command, but none of my application's jars. My application is deployed
in ${catalina.base}/myapp/. I tried to add a ${catalina.base}/myapp/
META-INF/context.xml file, but that wasn't loaded. Then I tried to add
<Resources>

     <JarResources
className="org.apache.catalina.webresources.JarResourceSet"
base="${catalina.base}/mycompany/WEB-INF/lib/my.jar" webAppMount="/" />
</Resources>

to context.xml but that didn't help either. It makes sense that Tomcat is
separating my application from the rest of the classpath but then how do I
include the required class?

Re: ClassNotFoundException when loading session from disk

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
Regarding the deployment location, you're right, it's unusual, but it's a
legacy application.

I found out the reason for the class not being visible. There was a Context
element with docBase defined in server.xml which I hadn't noticed. Nesting
the Manager element inside that (rather than in context.xml) solved the
issue.



On Tue, May 12, 2020 at 9:45 PM Mark Thomas <ma...@apache.org> wrote:

> On 12/05/2020 18:38, Jonathan Yom-Tov wrote:
> > I'm trying to use PersistentManager with FileStore to load sessions from
> > disk. Serialization goes ok but when the session is loaded I get an
> > exception deserializing one of my application's classes.
> >
> > [2020-05-12 09:08:52] [SEVERE] Session:
> > 6325A48BA1D2FC79105C7F4B0A76CB74.worker1;
> > java.lang.ClassNotFoundException: com.mycompany.MyClass
> >         at
> >
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
> >         at
> >
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
> >         at java.lang.Class.forName0(Native Method)
> >         at java.lang.Class.forName(Class.java:348)
> >         at
> >
> org.apache.catalina.util.CustomObjectInputStream.resolveClass(CustomObjectInputStream.java:159)
> >         at
> > java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1620)
> >         at
> > java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
> >         at
> > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
> >         at
> > java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
> >         at
> java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
> >         at
> >
> org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1576)
> >         at
> >
> org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1048)
> >         at org.apache.catalina.session.FileStore.load(FileStore.java:234)
> >
> > Looking into the classpath when the exception occurs I see that every jar
> > in ${catalina.base}/lib is loaded plus those explicitly mentioned in the
> > run command, but none of my application's jars.
>
> That is as expected. You want to look at the WebappClassLoader instance.
> Is that pointing to the right web application? If not, why not? Pay
> particular attention to the state field.
>
> > My application is deployed
> > in ${catalina.base}/myapp/. I tried to add a ${catalina.base}/myapp/
> > META-INF/context.xml file, but that wasn't loaded.
>
> That is an odd location. Why not in webapps?
>
> > Then I tried to add
> > <Resources>
> >
> >      <JarResources
> > className="org.apache.catalina.webresources.JarResourceSet"
> > base="${catalina.base}/mycompany/WEB-INF/lib/my.jar" webAppMount="/" />
> > </Resources>
>
> That should never be necessary.
>
> > to context.xml but that didn't help either. It makes sense that Tomcat is
> > separating my application from the rest of the classpath but then how do
> I
> > include the required class?
>
> If the correct web application class loader is picked up, is should just
> work.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: ClassNotFoundException when loading session from disk

Posted by jo...@hush.ai.INVALID.

On 5/12/2020 at 7:45 PM, "Mark Thomas"  wrote:On 12/05/2020 18:38,
Jonathan Yom-Tov wrote:
> I'm trying to use PersistentManager with FileStore to load sessions
from
> disk. Serialization goes ok but when the session is loaded I get an
> exception deserializing one of my application's classes.
> 
> [2020-05-12 09:08:52] [SEVERE] Session:
> 6325A48BA1D2FC79105C7F4B0A76CB74.worker1;
> java.lang.ClassNotFoundException: com.mycompany.MyClass
>         at
>
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
>         at
>
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:348)
>         at
>
org.apache.catalina.util.CustomObjectInputStream.resolveClass(CustomObjectInputStream.java:159)
>         at
>
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1620)
>         at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
>         at
>
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
>         at
> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
>         at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
>         at
>
org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1576)
>         at
>
org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1048)
>         at
org.apache.catalina.session.FileStore.load(FileStore.java:234)
> 
> Looking into the classpath when the exception occurs I see that
every jar
> in ${catalina.base}/lib is loaded plus those explicitly mentioned in
the
> run command, but none of my application's jars.

That is as expected. You want to look at the WebappClassLoader
instance.
Is that pointing to the right web application? If not, why not? Pay
particular attention to the state field.

> My application is deployed
> in ${catalina.base}/myapp/. I tried to add a ${catalina.base}/myapp/
> META-INF/context.xml file, but that wasn't loaded.

That is an odd location. Why not in webapps?

> Then I tried to add
> 
> 
>       className="org.apache.catalina.webresources.JarResourceSet"
> base="${catalina.base}/mycompany/WEB-INF/lib/my.jar" webAppMount="/"
/>
> 

That should never be necessary.

> to context.xml but that didn't help either. It makes sense that
Tomcat is
> separating my application from the rest of the classpath but then
how do I
> include the required class?

If the correct web application class loader is picked up, is should
just
work.

Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

Re: ClassNotFoundException when loading session from disk

Posted by Mark Thomas <ma...@apache.org>.
On 12/05/2020 18:38, Jonathan Yom-Tov wrote:
> I'm trying to use PersistentManager with FileStore to load sessions from
> disk. Serialization goes ok but when the session is loaded I get an
> exception deserializing one of my application's classes.
> 
> [2020-05-12 09:08:52] [SEVERE] Session:
> 6325A48BA1D2FC79105C7F4B0A76CB74.worker1;
> java.lang.ClassNotFoundException: com.mycompany.MyClass
>         at
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
>         at
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:348)
>         at
> org.apache.catalina.util.CustomObjectInputStream.resolveClass(CustomObjectInputStream.java:159)
>         at
> java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1620)
>         at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
>         at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
>         at
> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
>         at
> org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1576)
>         at
> org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1048)
>         at org.apache.catalina.session.FileStore.load(FileStore.java:234)
> 
> Looking into the classpath when the exception occurs I see that every jar
> in ${catalina.base}/lib is loaded plus those explicitly mentioned in the
> run command, but none of my application's jars.

That is as expected. You want to look at the WebappClassLoader instance.
Is that pointing to the right web application? If not, why not? Pay
particular attention to the state field.

> My application is deployed
> in ${catalina.base}/myapp/. I tried to add a ${catalina.base}/myapp/
> META-INF/context.xml file, but that wasn't loaded.

That is an odd location. Why not in webapps?

> Then I tried to add
> <Resources>
> 
>      <JarResources
> className="org.apache.catalina.webresources.JarResourceSet"
> base="${catalina.base}/mycompany/WEB-INF/lib/my.jar" webAppMount="/" />
> </Resources>

That should never be necessary.

> to context.xml but that didn't help either. It makes sense that Tomcat is
> separating my application from the rest of the classpath but then how do I
> include the required class?

If the correct web application class loader is picked up, is should just
work.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org