Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Drools-classcastexception-when-tomcat-upgraded-from-tomcat-7-to-tomcat-9

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Facing issues with drools jars when upgrading tomcat to tomcat9.

I had a drools based rule engine deployed in a tomcat 7. I was using 7.28.0.Final for drools.

When I upgraded the tomcat to tomcat 9, it started giving me following exception



Then I upgraded the Drools to much higher version 7.49.0.Final and now I am getting same error but for some other class.

 
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat doesn't know anything about Drools. From the looks of things, it appears that your application build process isn't including all the necessary Drools libraries.
 
Abhishek Kumar
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked my actual deployment.

I verified the WEB-INF\lib of my application. The classes which are getting Classcastexception like BigDecimalSumAccumulateFunction, they are present in one of the jars.

BigDecimalSumAccumulateFunction is part of drools-core jar and its there in WEB-INF lib. So, not sure why I am still getting this classcastException.


Also, If I run the same webapp with tomcat7, it works fine. Somehow when I try to run the same APP in tomcat9, it gets into these problems
 
Tim Holloway
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the TOMCAT_HOME/lib directory to make sure that no Drools code - or other application code - was placed there. That could interfere with class location.

When Tomcat deploys a web application, it scans the app's WEB-INF/classes and WEB-INF/lib directories and adds their contents to the webapp's classpath unconditionally. So if your WEB-INF/lib contains the expected classes and you don't have conflicts with the Tomcat lib directory, then the next logical step is to determine whether you're really accessing the webapp instance that you think you are. First verify that the URL you are using points to the server your app is supposed to be in, then make sure that you don't have stale/duplicate instances of the app deployed. Check the files in TOMCAT_HOME/conf/Catalina/locahost. Stop Tomcat, removing all files in TOMCAT_HOME/work, TOMCAT_HOME/temp, TOMCAT_HOME/webapps and TOMCAT_HOME/logs. Then re-deploy your Drools app's WAR/restart Tomcat.
 
Abhishek Kumar
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked the folder you mentioned it looks clean.

Infact, if i run the code in my eclipse as web project then also i face the same issue. If i run with tomcat9 it gives the mentioned issues and If I run the 100% same code with tomcat 7 it runs successfully.

Infact while using tomcat 9 I debugged and it really gets into ClassNotforundException multiple times and looks its for Drools libraries only at start of the tomcat.

I also tried deploying the war file in windows tomcat and result is same. This is really clueless.

Somehow I feel when tomcat is upgraded, there is some other jars apart from Drools too which needs to be upgraded. Like its showing exception for Drools classes but might be Tomcat 9 is looking for some other classes pointed by those classes. Not getting any clue for now.
 
Tim Holloway
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said, Tomcat doesn't know anything at all about Drools. It's also self-contained, so you don't have any "extra" updates to Tomcat when you upgrade Tomcat.

You might want to check which versions of Java you are running and whether you get different results from different Java versions.

It sounds like you were also having the problem when running stand-alone, which would definitely mean it's not a Tomcat problem.

If you're using Maven to build the app, it might be a good idea to paste in a copy of the POM file you're building with.

Also, just as a reminder, Java does not look for classes inside JARs that are inside of JARs.
 
Abhishek Kumar
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It sounds like you were also having the problem when running stand-alone, which would definitely mean it's not a Tomcat problem.



Sorry for the confusion here. I did not mean to say that I was running it as standalone. I meant to say that I was getting exceptions even when I wan in Eclipse's or Windows's tomcat. At the end, it was still a tomcat.

Also, Java version is 1.8 everywhere.

Strangest thing is when I put the same war file tomcat 7 it works, but it does not work in tomcat 9.

That kinda hints me that Drools might be using some class/jar of tomcat which might not be  present in tomcat 9. I am not able to figure out which class that can be.

Just for that reason, I don't think it has much to do with pom as same war file with same set of dependents work in tomcat 7 but does not work in tomcat 9

I have 2 levels of pom I am attaching all of them if that helps.




Pom pf parent 1

<properties>
<drools.runtime.version>7.28.0.Final</drools.runtime.version>
<cdi.version>1.2</cdi.version>
<weld.version>2.4.8.Final</weld.version>
</properties>

<dependencies>
<dependency>
<groupId>a</groupId>
<artifactId>cm-modelMapping-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${drools.runtime.version}</version>
</dependency>
<!-- <dependency> <groupId>org.kie</groupId> <artifactId>kie-internal</artifactId> <br /> <version>6.2.0.Final</version> </dependency> -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-templates</artifactId>
<version>${drools.runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.runtime.version}</version>
</dependency>

<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools.runtime.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->

<!-- END -->
</dependencies>

Pom of parent 2



pom of main web project


 
Tim Holloway
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Drools has absolutely no business knowing anything about the classes internal to any version of Tomcat. As far as I can recall, it doesn't even need to know that much about general JEE HTTP protocols and services.

Speaking of which, you're including part of jetty in your POM. The jetty webapp server and Tomcat webapp server are two distinctly different products. You're also including mockito in at "compile" scope. Pretty sure that would end up including what is supposed to be test-only code into the production build.

Also, I thought that Weld was obsolete.  

When Drools cannot find classes that belong to Drools, it's far more likely that the problem is in how you are using Drools than it is Tomcat. Tomcat is a basic webapp server and it knows nothing about application frameworks. It handles the network traffic, HTTP(S) protocols, database connection pools, basic JNDI services and that's all. Everything else has to be handled by the webapps.
 
Abhishek Kumar
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that but I also want to emphasize that I am able to run the exactly same war file say abc.war when I put it in webapps of tomcat 7 but it gives ClassNotFoundException when I put the same abc.war in webapps of tomcat 9.


Speaking of which, you're including part of jetty in your POM. The jetty webapp server and Tomcat webapp server are two distinctly different products. You're also including mockito in at "compile" scope. Pretty sure that would end up including what is supposed to be test-only code into the production build.



I am able to run the war file created out of same pom in tomcat 7.


I also doubted jetty specially when it ws eclipse's Jetty. I actually tried that earlier. I removed jetty and tried too. That does not help.

Do you thing I can try something else too.

 
Tim Holloway
Saloon Keeper
Posts: 23252
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can say nothing further without actually having my sweaty hands on the project source code. Which would probably offend your employers besides being more work than I would do withut payment.

I found a Google Group that might be able to help you, though: https://groups.google.com/g/drools-setup
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic