Reputation: 120376
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.
Upvotes: 2
Views: 4744
Reputation: 1
A stupid mistake I made was that I needed to reload the webapp before the jar I copied into WEB-INF/lib would be loaded (i.e. either restarting entire Tomcat server, or reload just the specific app from the Tomcat manager). Dynamically editing the .groovy files right inside the Tomcat/webapps/ dir and seeing the updates to pages immediately lulled me into the feeling that everything would be auto-loaded, but not so with jars. It was maddening until I realized what was going on.
Upvotes: 0
Reputation:
I'm using Groovy plugin for Eclipse. Exporting Groovlets in a war file does also work.
When I do export my Groovlet-based application, this helpful plugin puts .groovy files in the /WEB-INF/classes directory (in the classpath). And it works when I deploy the war file in my Tomcat Server.
Hope that this helps.
Regards.
Upvotes: 1