I'm having some trouble running a groovy servlet (groovlet) in tomcat that imports a library class. When I don't import anything the groovlet works correctly, but if I do import something that I expect to be on the classpath (I can import the same class successfully in a regular servlet), I see the following error:
groovy.util.ScriptException: Could not parse scriptName: /MyGroovlet.groovy
java.lang.RuntimeException: groovy.util.ScriptException: Could not parse scriptName: /MyGroovlet.groovy
at groovy.servlet.GroovyServlet$1.call(GroovyServlet.java:123)
...
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, /MyGroovlet.groovy: 1: unable to resolve class com.mycompany.mypackage.MyLibraryClass
@ line 1, column 1.
The jar containing MyLibraryClass
is in shared/lib
, which is loaded by tomcat by the following in catalina.properties
:
shared.loader=...,${catalina.base}/shared/lib/*.jar,...
My groovlets are mapped as described in the user guide in my application's web.xml
:
<servlet>
<servlet-name>GroovyServlet</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GroovyServlet</servlet-name>
<url-pattern>*.groovy</url-pattern>
</servlet-mapping>
And here's the code for the groovlet, MyGroovlet.groovy
:
import com.mycompany.mypackage.MyLibraryClass
MyLibraryClass.someStaticMethod()
My groovlet is deployed to WEB-INF/groovy/MyGroovlet.groovy
, per the GroovyServlet API.
When I visit http://localhost:8080/myapplication/MyGroovlet.groovy
, the error described previously is written to my application logs.
Is there some way that I need to explicitly declare the runtime classpath for GroovyServlet? I've tried moving the library jar to several places, including WEB-INF/lib
and moving the actual MyLibraryClass.class
file to WEB-INF/classes
, but with no luck.