Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » How to exclude Groovy plugin jars from Tomcat classpath
How to exclude Groovy plugin jars from Tomcat classpath [message #1210470] Tue, 26 November 2013 01:48 Go to next message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
I have a Spring MVC project that uses Maven imported into Eclipse Kepler SR1 JEE and deployed to Tomcat 7 within Eclipse. Everything was fine until I recently added elasticsearch as a dependency to the Maven pom file and now when I start Tomcat I get an exception
java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servlet.Servlet


Launching the server in verbose mode, I see that its because the servlet API is now being loaded from 2 places:
the Tomcat installation folder where it normally comes from
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/apache-tomcat-7.0.33/lib/servlet-api.jar


but also from the Groovy plugin I have installed
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar


I can't figure out why this is happening. If I rename the servlet jar file in the plugin's lib folder (i.e. change the extension from .jar to something else so that its not recognized), Tomcat starts up without an exception but that's a hack and so I'd like to know what the cause is and if I'm missing some WTP configuration to exclude plugin library jars from the Tomcat classpath.

Thanks.
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1219227 is a reply to message #1210470] Mon, 02 December 2013 18:27 Go to previous messageGo to next message
Eclipse UserFriend
On 11/25/2013 8:48 PM, steve B wrote:
> I have a Spring MVC project that uses Maven imported into Eclipse Kepler
> SR1 JEE and deployed to Tomcat 7 within Eclipse. Everything was fine
> until I recently added elasticsearch as a dependency to the Maven pom
> file and now when I start Tomcat I get an exception
> java.lang.ClassCastException:
> org.springframework.web.servlet.DispatcherServlet cannot be cast to
> javax.servlet.Servlet
>
> Launching the server in verbose mode, I see that its because the servlet
> API is now being loaded from 2 places:
> the Tomcat installation folder where it normally comes from
> Loaded javax.servlet.Servlet from
> file:/C:/ProgramFiles/apache-tomcat-7.0.33/lib/servlet-api.jar
>
> but also from the Groovy plugin I have installed
> Loaded javax.servlet.Servlet from
> file:/C:/ProgramFiles/eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
>
>
> I can't figure out why this is happening. If I rename the servlet jar
> file in the plugin's lib folder (i.e. change the extension from .jar to
> something else so that its not recognized), Tomcat starts up without an
> exception but that's a hack and so I'd like to know what the cause is
> and if I'm missing some WTP configuration to exclude plugin library jars
> from the Tomcat classpath.
>
> Thanks.

Try using a later version of Groovy, that supports the servlet API that
matches your version of Tomcat.

The latest version of Groovy is 2.2.1 - at least 5 or 6 releases beyond
what you have.

Otherwise, you'll have to rename the jar to avoid the collision.
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1219828 is a reply to message #1219227] Fri, 06 December 2013 06:50 Go to previous messageGo to next message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
I do have Groovy 1.8.6 installed but the jar is being loaded from the Eclipse Groovy plugins folder.

Nonetheless, I followed your suggestion and installed Groovy 2.2.1, updated my path and restarted Eclipse. The Servlet class is no longer being reloaded from the 2.4 servlet jar but I got a LinkageError for ServletResponse which is being loaded from the servlet 2.4 jar from the 1.8.6 plugin
java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/catalina/loader/WebappClassLoader) previously initiated loading for a different type with name "javax/servlet/ServletResponse"


I have the latest version of the Groovy plugin (2.8.0.xx-20130703-1600-e43-RELEASE) which includes 2 versions of Groovy both of which have the servlet 2.4 jar at
eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
and
eclipse/plugins/org.codehaus.groovy_2.0.7.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar

I found that the plugin compiler version can be updated to 2.1 by installing the Groovy Compiler 2.1 feature so I did that. This version also includes servlet 2.4 jar (eclipse/plugins/org.codehaus.groovy_2.1.5.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar) but the servlet class is still loaded from the jar in the 1.8.6 plugin's folder.

Thanks for your help, updating the version looked very promising but unfortunately didn't work.
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1219906 is a reply to message #1219828] Fri, 06 December 2013 15:21 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 12/6/2013 1:50 AM, steve B wrote:
> I do have Groovy 1.8.6 installed but the jar is being loaded from the
> Eclipse Groovy plugins folder.
>
> Nonetheless, I followed your suggestion and installed Groovy 2.2.1,
> updated my path and restarted Eclipse. The Servlet class is no longer
> being reloaded from the 2.4 servlet jar but I got a LinkageError for
> ServletResponse which is being loaded from the servlet 2.4 jar from the
> 1.8.6 plugin
> java.lang.LinkageError: loader constraint violation: loader (instance of
> org/apache/catalina/loader/WebappClassLoader) previously initiated
> loading for a different type with name "javax/servlet/ServletResponse"
>
> I have the latest version of the Groovy plugin
> (2.8.0.xx-20130703-1600-e43-RELEASE) which includes 2 versions of Groovy
> both of which have the servlet 2.4 jar at
> eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
>
> and
> eclipse/plugins/org.codehaus.groovy_2.0.7.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
>
>
> I found that the plugin compiler version can be updated to 2.1 by
> installing the Groovy Compiler 2.1 feature so I did that. This version
> also includes servlet 2.4 jar
> (eclipse/plugins/org.codehaus.groovy_2.1.5.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar)
> but the servlet class is still loaded from the jar in the 1.8.6 plugin's
> folder.
>
> Thanks for your help, updating the version looked very promising but
> unfortunately didn't work.

If you are using the Web Tools Tomcat server, do you have the "Serve
modules without publishing" option enabled? The fact that the
servlet-api-2.4.jar is being accessed directly suggests that this might
be so.

Cheers,
Larry
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1219943 is a reply to message #1219906] Sat, 07 December 2013 02:37 Go to previous messageGo to next message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
Hi Larry, I am using the Web Tools Tomcat server and the "Serve modules without publishing" option is disabled. I tried with it enabled just to try but it didn't make a difference.

Thanks for the suggestion.
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1220115 is a reply to message #1219943] Mon, 09 December 2013 20:06 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 12/6/2013 9:37 PM, steve B wrote:
> Hi Larry, I am using the Web Tools Tomcat server and the "Serve modules
> without publishing" option is disabled. I tried with it enabled just to
> try but it didn't make a difference.
>
> Thanks for the suggestion.

This means I have no idea why your Tomcat startup would include:

Loaded javax.servlet.Servlet from
file:/C:/ProgramFiles/eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar

I know of no way other than the "Serve modules without publishing"
option that Tomcat startup would access a jar under
"file:/C:/ProgramFiles/eclipse/plugins".

I would suggest unzipping a fresh Tomcat 7 into some new location and
use it to create a new runtime and server in WTP. This will ensure that
everything about the server is created with default settings. Try
running your webapp project on this server and see if you encounter the
same problem.

Cheers,
Larry
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1220138 is a reply to message #1220115] Tue, 10 December 2013 04:34 Go to previous messageGo to next message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
Downloaded the latest Tomcat and created a new runtime and server config in WTP but I got the LinkageError for "javax/servlet/ServletResponse".

It seems that Maven/m2e is somehow involved in this because I don't get the error if I remove the elasticsearch dependency from the pom, this started happening only after adding that dependency. Looking at the dependency hierarchy when I view the pom in Eclipse, elasticsearch doesn't have a dependency on anything other than Lucene so its unclear why it has an effect on the server classpath.

Thanks,
Steve
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1220439 is a reply to message #1220138] Wed, 11 December 2013 17:51 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 12/9/2013 11:34 PM, steve B wrote:
> Downloaded the latest Tomcat and created a new runtime and server config
> in WTP but I got the LinkageError for "javax/servlet/ServletResponse".
>
> It seems that Maven/m2e is somehow involved in this because I don't get
> the error if I remove the elasticsearch dependency from the pom, this
> started happening only after adding that dependency. Looking at the
> dependency hierarchy when I view the pom in Eclipse, elasticsearch
> doesn't have a dependency on anything other than Lucene so its unclear
> why it has an effect on the server classpath.
>
> Thanks,
> Steve

If you look at the published webapp under
"<workspace>/.metadata/.plugins/org.eclipse.wst.server.core/tmp?/wtpwebapps",
do you see "servlet-api" jar(s) included in its "WEB-INF/lib"?

While it is technically not correct to include a servlet-api jar in
WEB-INF/lib of a webapp, Tomcat tries to help out by ignoring the jar.
If this is occurring, you would see an INFO message in the console log
like the following:

INFO: validateJarFile(<path to jar>) - jar not loaded. See Servlet Spec
2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

Are you seeing this?

Cheers,
Larry
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1220480 is a reply to message #1220439] Thu, 12 December 2013 04:53 Go to previous messageGo to next message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
Hi Larry, there isn't a servlet api jar at that location (or anywhere under org.eclipse.wst.server.core) and none of the INFO messages are related to servlet.
I'm using JDK 1.6, I don't know if that matters.

thanks,
Steve
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1220573 is a reply to message #1220480] Thu, 12 December 2013 15:13 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 12/11/2013 11:53 PM, steve B wrote:
> Hi Larry, there isn't a servlet api jar at that location (or anywhere
> under org.eclipse.wst.server.core) and none of the INFO messages are
> related to servlet.
> I'm using JDK 1.6, I don't know if that matters.
>
> thanks,
> Steve

Steve,

This eliminates there being multiple servlet-api jars running around as
a possible cause of the LinkageError. Instead, it would seem that
elasticsearch is playing some "classloader games" and managing to shoot
itself in the foot when used within a webapp (i.e. the same class loaded
in different classloaders can't be used interchangeably). You may have
to ask elasticsearch support for info about solving this. I'm not sure
if there is anything to be done to the project to avoid this other than
not using elasticsearch. Sorry I couldn't be of more help.

Cheers,
Larry
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1235109 is a reply to message #1220573] Thu, 23 January 2014 15:38 Go to previous messageGo to next message
Guillermo Mazzola is currently offline Guillermo MazzolaFriend
Messages: 1
Registered: January 2014
Junior Member
Hi there, I'm having the same issue here:
java.lang.LinkageError if I start the ElasticSearch client on my Spring Web Applicaiton.

Then I found that the cause was Groovy's plugin, wich I dont know why is on the Tomcat's context classpath.

I've reported a bug on ES, but not response yet.
https //github.com/ocpsoft/prettytime/issues/55

Any ideas?
Re: How to exclude Groovy plugin jars from Tomcat classpath [message #1236807 is a reply to message #1220573] Tue, 28 January 2014 05:22 Go to previous message
steve B is currently offline steve BFriend
Messages: 8
Registered: July 2009
Junior Member
Larry, thanks very much for your time looking into this. Since there isn't an alternative, I've renamed the servlet api jars in the groovy plugin folders. It doesn't seem to affect my project and elasticsearch works so it'll have to do.

Thanks again,
Steve
Previous Topic:JSDT: Cursor Jumping to Constructor Function
Next Topic:(Solved)The solution for the conflict when Config Glassfish 4 with the Kepler on MAC OS X 10.9.1
Goto Forum:
  


Current Time: Thu Apr 25 17:49:09 GMT 2024

Powered by FUDForum. Page generated in 0.04436 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top