Groovlet + Tomcat: "unable to resolve class" when importing libraries

I'm having trouble running the groovy (groovlet) servlet in tomcat that imports the library class. When I don't import anything the groovlet works correctly, but if I import something that I expect to be on the classpath (I can import the same class into 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 box containing MyLibraryClass

is in shared/lib

, which is loaded by tomcat like this catalina.properties

::

shared.loader=...,${catalina.base}/shared/lib/*.jar,...

      

My groovlets are rendered as described in the user guide in my app 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 Groovlet, MyGroovlet.groovy

:

import com.mycompany.mypackage.MyLibraryClass
MyLibraryClass.someStaticMethod()

      

My groovlet is deployed to WEB-INF/groovy/MyGroovlet.groovy

, behind the GroovyServlet API .

When I visit http://localhost:8080/myapplication/MyGroovlet.groovy

, the above error is written to application logs.

Is there some way I have to explicitly declare for the GrooveyServlet class for the runtime class? I've tried moving the library to multiple locations, including WEB-INF/lib

moving the actual file MyLibraryClass.class

to WEB-INF/classes

, but no luck.

+1


source to share


2 answers


I am using the Groovy plugin for Eclipse. Exporting Groovlets to war file also works.

When I export my Groovlet application, this useful plugin places the .groovy files in the / WEB-INF / class directory (in the classpath). And it works when I deploy the war file to my Tomcat Server.



Hope it helps.

Sincerely.

+1


source


The dumb mistake I made was that I needed to reload the webapp before the jar that I copied to WEB-INF / lib was loaded (for example, restarting the entire Tomcat server, or reloading only a specific application from the Tomcat manager). Editing the .groovy files dynamically right inside Tomcat / webapps / dir and seeing the updates on the pages immediately lulls me to the point that everything will be loaded automatically, but not so with the jars. It was crazy until I realized what was going on.



0


source







All Articles