1

I have this scenario:

  1. //Tomcat7/webapps/app1/WEB-INF/classes/a/b/c/A.class
  2. //Tomcat7/webapps/app1/WEB-INF/classes/a/b/c/B.class
  3. //Tomcat7/webapps/app2/WEB-INF/classes/a/b/c/B.class (different class but same name as <2>)
  4. //Tomcat7/webapps/app2/WEB-INF/classes/a/b/c/C.class

Note: class directory hierarchy is the same, just the class file is different.

The log file for app1 contains NoClassDefFoundError for A.class. Checked the directory, class file definitely is there. Now I am trying to figure out if it is possible that the ClassLoader loaded only B.class and not A.class, although there should be a ClassLoader for each webapps - meaning two ClassLoaders?

Any ideas how this works?

EDIT: Tomcat7 is started via Tanuki JWS. From wrapper.log, I can see that app2 is initialized first, then only app1.

Regards, Allan

allancth
  • 300
  • 3
  • 15
  • If I remember well, Tomcat manage classpath for each application separatly, so a Class from app1 can not be hidden by a Class with same name from app2. – lpratlong Jun 04 '14 at 09:13
  • It works as documented: http://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html – Gimby Jun 04 '14 at 09:23
  • Will this also be the same if Tanuki JSW is used to start the container? – allancth Jun 04 '14 at 09:39
  • You really seem bent on blaming the tools you're using. I would stop that unless you have at least some proof that it may be true, its more in your benefit to want it to be something that you personally do wrong so you can fix it. I'll make an example: you checked if there is a file A.class. Good. Did you check if it is larger than 0 bytes? – Gimby Jun 04 '14 at 09:44
  • I'm not blaming on the tools that are being used. I am trying to understand the environment and if they affect each other and how. That's why I asked here if anyone has encountered it before. If I have proof I would have already posted it. And yes it's larger than 0 bytes. Trying to decompile the class now if to see the class is not corrupted or something. – allancth Jun 04 '14 at 09:48
  • Could it be by any chance that B.class is also contained in Tomcat common libs? That way Tomcat standard classloader would load B, but would not A. – Pavel S. Jun 04 '14 at 10:23
  • @PavelS That could be a problem if A or B class resides at the same package that has already been loaded, as I understand. Correct me if I am wrong though. – allancth Jun 04 '14 at 10:35
  • @allancth you are correct, the fully qualified classname is what matters and that is package + classname. Otherwise java.util.Date and java.sql.Date also would be an impossibility. Your situation is really quite puzzling, unless a jar with a/b/c/B.class also accidentally ended up in the shared classloader of tomcat/lib. – Gimby Jun 20 '14 at 13:14
  • @Gimby Yes it mystified me too. But our support engineer said everything works fine after the restart, so I am not going to dive into this any more, since I also doubt Tanuki JSW is the root cause. Well, cheers. – allancth Jun 20 '14 at 17:20

1 Answers1

0

This issue was solved after Tomcat7 was restarted. Root cause cannot be identified.

allancth
  • 300
  • 3
  • 15
  • Perhaps the webapp was reloaded, that might cause issues especially when there are static class members in play. – Gimby Jun 22 '14 at 16:16