You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Carles Franquesa <ca...@algorismes.cat> on 2020/09/01 18:08:26 UTC

Class loader does not find class in WEB-INF/classes

Hi,

This message is a reply to those that asked me for uploading a simple
version of my webapp reproducing the problem of not finding classes when a
JSP is inside a subfolder, thus not hanging directly from web root
directly.

I have slimmed down the code as much as possible. You'll see is almost
nothing.

 algorismes.zip
<https://drive.google.com/file/d/1RUanXza2wjCBQimjum-LlbGNaYP6vs4O/view?usp=drive_web>


So, the project's became very simple, but the problem is there:

Built with NetBeans 8.0.2 on Windows 10
Tested on local host (so tomcat running on windows), it works
My VPS holds a public web domain called algosismes.cat.
Tested on my VPS, it depends.

Once deploy's done with tomcat 8.5.57 manager app, clicking on its list of
sites, it works, since the browser is connecting to the ip:port/algorismes.

Setting directly "algorismes.cat" in the browser url, the error is found.
Just click to go to the level2.jsp.

Lervel2.jsp is a blank page that just declares ann object of class Student
to show the problem.

Anybody can explain to me what am i doing wrong?

Thanks you all!

Carles

Re: Class loader does not find class in WEB-INF/classes

Posted by Carles Franquesa <ca...@algorismes.cat>.
Missatge de Mark Eggers <it...@yahoo.com.invalid> del dia dt., 1 de
set. 2020 a les 21:47:

> Carles,
>
>
> On 9/1/2020 11:23 AM, Christopher Schultz wrote:
> > Carles,
> >
> > On 9/1/20 14:08, Carles Franquesa wrote:
> >> This message is a reply to those that asked me for uploading a
> >> simple version of my webapp reproducing the problem of not finding
> >> classes when a JSP is inside a subfolder, thus not hanging directly
> >> from web root directly.
> >
> >> I have slimmed down the code as much as possible. You'll see is
> >> almost nothing.
> >
> >> algorismes.zip
> >> <https://drive.google.com/file/d/1RUanXza2wjCBQimjum-LlbGNaYP6vs4O/vie
> > w?usp=drive_web>
> >
> >
> >
> >> So, the project's became very simple, but the problem is there:
> >
> >> Built with NetBeans 8.0.2 on Windows 10 Tested on local host (so
> >> tomcat running on windows), it works My VPS holds a public web
> >> domain called algosismes.cat. Tested on my VPS, it depends.
> >
> >> Once deploy's done with tomcat 8.5.57 manager app, clicking on its
> >> list of sites, it works, since the browser is connecting to the
> >> ip:port/algorismes.
> >
> >> Setting directly "algorismes.cat" in the browser url, the error is
> >> found. Just click to go to the level2.jsp.
> >
> >> Lervel2.jsp is a blank page that just declares ann object of class
> >> Student to show the problem.
> >
> >> Anybody can explain to me what am i doing wrong?
> >
> > The ZIP file does not contain a build web application. Can you publish
> > your WAR file instead of mixed source/resources?
> >
> > It's pretty important how you build the WAR, which is why I'm asking
> > for it.
> >
> > -chris
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> There are a lot of issues with your project that have nothing to do with
> Tomcat. I'm going to assume that most of your project problems exist
> because of how aggressively you stripped down your project.
>

I don't know what are you referring to.  But I would like to!


> As a start, you'll need to set up your project correctly in NetBeans.
>
> Instead of just copying the commons-fileupload-1.3.jar and
> commons-io-2.2.jar into WEB-INF/lib, you'll need to add them to your
> project.
>

I was not sure where to put them, and now they are in both places.



>
> Right-mouse on the project, then:
>
> Properties->Libraries
> Click on the Add Jar / Folder button
>

Already did that.



>
> Browse to your jar files and add them. Then when NetBeans builds the
> project, they will be included in the war file.
>

Thanks for clarify me about this.



>
> I've checked, and all of the files are in the proper place in the built
> war file.


> Now some project notes:
>
> 1. Start with using NetBeans 12 - netbeans.apache.org
>
> I will do it.




> 2. Seriously consider using a Maven-based project instead of an
> Ant-based project
>

Perhaps may be because I am too old, but I am not used to this reference
managers. I don't use maven neither gradle,... I work in an old fashioned
way!



> This will make dependency management much easier.
>
> 3. Seriously consider using the NetBeans built-in CDNJS manager for
> JavaScript libraries
> This will make JavaScript dependency management much easier.
>

If this is one of my problems, I do not realize it.


> 4. Do not use generic top-level package names. Consider starting
> everything with org.franquesa.
>

Why?



>
> 5. Do not manage database access on your own. Use JNDI and Tomcat's
> pooling.
> See: http://tomcat.apache.org/tomcat-8.5-doc/jndi-resources-howto.html


I like to use database access on my own. Is this a problem? Sorry for my
ignorance, but I only change the way I work when I understand why I do it.



>
>
> See Christopher Schultz's excellent document on how to properly handle
> pooled JDBC connections:
>
>
> https://blog.christopherschultz.net/2009/03/16/properly-handling-pooled-jdbc-connections/
>
> Thanks. Just read it, and will try to modify the code accordingly, since
have already had this kind of leaks.



> Yes, there are reasons to manage your own database pooling, but there
> are not that many use cases for it.
>

I would thank you for unwrapping this. I can't imagine which use cases are
you talking on.



> PS: I fixed some obvious typos in your posted project, built it, and ran
>

Also, would like to know which typos you say.



> it on Tomcat 9.0.37 and JDK 11 on a local internal system (not
> localhost). I was able to successfully click on the first page and
> navigate to the second page (/appname/folder/level2.jsp).
>
>
Thanks for your words. It's been very useful. This is certainly an
illustrative mail!


Carles

Re: Class loader does not find class in WEB-INF/classes

Posted by Mark Eggers <it...@yahoo.com.INVALID>.
Carles,


On 9/1/2020 11:23 AM, Christopher Schultz wrote:
> Carles,
> 
> On 9/1/20 14:08, Carles Franquesa wrote:
>> This message is a reply to those that asked me for uploading a
>> simple version of my webapp reproducing the problem of not finding
>> classes when a JSP is inside a subfolder, thus not hanging directly
>> from web root directly.
> 
>> I have slimmed down the code as much as possible. You'll see is
>> almost nothing.
> 
>> algorismes.zip
>> <https://drive.google.com/file/d/1RUanXza2wjCBQimjum-LlbGNaYP6vs4O/vie
> w?usp=drive_web>
> 
> 
> 
>> So, the project's became very simple, but the problem is there:
> 
>> Built with NetBeans 8.0.2 on Windows 10 Tested on local host (so
>> tomcat running on windows), it works My VPS holds a public web
>> domain called algosismes.cat. Tested on my VPS, it depends.
> 
>> Once deploy's done with tomcat 8.5.57 manager app, clicking on its
>> list of sites, it works, since the browser is connecting to the
>> ip:port/algorismes.
> 
>> Setting directly "algorismes.cat" in the browser url, the error is
>> found. Just click to go to the level2.jsp.
> 
>> Lervel2.jsp is a blank page that just declares ann object of class
>> Student to show the problem.
> 
>> Anybody can explain to me what am i doing wrong?
> 
> The ZIP file does not contain a build web application. Can you publish
> your WAR file instead of mixed source/resources?
> 
> It's pretty important how you build the WAR, which is why I'm asking
> for it.
> 
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

There are a lot of issues with your project that have nothing to do with
Tomcat. I'm going to assume that most of your project problems exist
because of how aggressively you stripped down your project.

As a start, you'll need to set up your project correctly in NetBeans.

Instead of just copying the commons-fileupload-1.3.jar and
commons-io-2.2.jar into WEB-INF/lib, you'll need to add them to your
project.

Right-mouse on the project, then:

Properties->Libraries
Click on the Add Jar / Folder button

Browse to your jar files and add them. Then when NetBeans builds the
project, they will be included in the war file.

I've checked, and all of the files are in the proper place in the built
war file.

Now some project notes:

1. Start with using NetBeans 12 - netbeans.apache.org

2. Seriously consider using a Maven-based project instead of an
Ant-based project
This will make dependency management much easier.

3. Seriously consider using the NetBeans built-in CDNJS manager for
JavaScript libraries
This will make JavaScript dependency management much easier.

4. Do not use generic top-level package names. Consider starting
everything with org.franquesa.

5. Do not manage database access on your own. Use JNDI and Tomcat's pooling.
See: http://tomcat.apache.org/tomcat-8.5-doc/jndi-resources-howto.html

See Christopher Schultz's excellent document on how to properly handle
pooled JDBC connections:

https://blog.christopherschultz.net/2009/03/16/properly-handling-pooled-jdbc-connections/

Yes, there are reasons to manage your own database pooling, but there
are not that many use cases for it.

PS: I fixed some obvious typos in your posted project, built it, and ran
it on Tomcat 9.0.37 and JDK 11 on a local internal system (not
localhost). I was able to successfully click on the first page and
navigate to the second page (/appname/folder/level2.jsp).


Re: Class loader does not find class in WEB-INF/classes

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Carles,

On 9/1/20 14:08, Carles Franquesa wrote:
> This message is a reply to those that asked me for uploading a
> simple version of my webapp reproducing the problem of not finding
> classes when a JSP is inside a subfolder, thus not hanging directly
> from web root directly.
>
> I have slimmed down the code as much as possible. You'll see is
> almost nothing.
>
> algorismes.zip
> <https://drive.google.com/file/d/1RUanXza2wjCBQimjum-LlbGNaYP6vs4O/vie
w?usp=drive_web>
>
>
>
> So, the project's became very simple, but the problem is there:
>
> Built with NetBeans 8.0.2 on Windows 10 Tested on local host (so
> tomcat running on windows), it works My VPS holds a public web
> domain called algosismes.cat. Tested on my VPS, it depends.
>
> Once deploy's done with tomcat 8.5.57 manager app, clicking on its
> list of sites, it works, since the browser is connecting to the
> ip:port/algorismes.
>
> Setting directly "algorismes.cat" in the browser url, the error is
> found. Just click to go to the level2.jsp.
>
> Lervel2.jsp is a blank page that just declares ann object of class
> Student to show the problem.
>
> Anybody can explain to me what am i doing wrong?

The ZIP file does not contain a build web application. Can you publish
your WAR file instead of mixed source/resources?

It's pretty important how you build the WAR, which is why I'm asking
for it.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl9OkbIACgkQHPApP6U8
pFg7dg/6AmyQSP5Xuz8p8gwgyvZ5Sysn7oa+7TNqRQ0Q5PGdEC+7AbIb9B8k99cB
ESzJIH5k7AeacTFmhwlUxEs76slnpn/MshYLhfpWXjcYEDcnKA+Q5vBIKQiEzbGP
PsGS8lHJzSHgBM0XDjxIrnMKjSgWGIVeibiSecHv10DayUC/jY6HohSqexdZtGk4
dTH8LrUdAvbIhNp0CaT1CNlE0MaMu80tJJs1ENETlHYesywx1OVMIPE+GcPC/EC3
jEyBHEXTgvUWBXWh2xom8Jb70gvaSXr6Q3f2C9OgOWZcVB8e/3y6pLwc82AawHoq
tkr69sjOqUgp/EqUsFatD+8xUtly6ip14pzW5+8dCWBvNQYQiAgzRcP85SNBsTN6
+bThfsD29aMNZ0nRYYELihq0RprG+gNgU6wLqeM5g7VpOi2D9EqCJMLOR47XzHAQ
aiaTHhao2r2Z+tzl0BlYfsVws08SL+lLkUxlHF0g3obigRg8DXE7ouOam4w4SB54
bbjHldgvAvRGahsbHNmUBh4tsh53mFud+OuFMgDw8g5urV+FqAqlviktDsGolVwv
C8yUkMUOklx/R5uPKCIoxTnkl0nV5fUd90YdpkKPg7bnd3XHBrauRlEyrZUk34Oo
Kt0LmpyiolI+eYL4ZdwMqDQLNjx8jTQTiGqn+stgOf3PvdzMjFU=
=ZVdV
-----END PGP SIGNATURE-----

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