Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Trying to get Eclipse + Tomcat + Groovy to work
Trying to get Eclipse + Tomcat + Groovy to work [message #227549] Sat, 07 February 2009 03:35 Go to next message
Mike Schwager is currently offline Mike SchwagerFriend
Messages: 3
Registered: July 2009
Junior Member
Hi,
I have created a Servlet using Eclipse J2EE version 3.4.1 and Tomcat 6.0.
I also installed Groovy 1.5.7 and added the Grooviness to Eclipse, and
added the Groovy nature to my project.

I can create a Groovy or Java project and run a Groovy application in
Eclipse. But I cannot run Groovy in a servlet.

I created a small working servlet in Java. What I would like to do next
is create a class in Groovy, then instantiate that class in my Java code.
Like the following (in here, KMLbuilder is a very simple Groovy class).
The question is, how can I get Groovy to work in a Tomcat Servlet, within
the Eclipse development environment?

public class Play extends HttpServlet {
private static final long serialVersionUID = 1L;

public KMLbuilder KMLbuilder;
public Play() {
super();
}

public void init(ServletConfig config) throws ServletException {
KMLbuilder = new KMLbuilder();
}
...
}
I get the following error in the Eclipse web browser when I try to execute
this

javax.servlet.ServletException: Error instantiating servlet class
com.schwager.Play
...
root cause

java.lang.NoClassDefFoundError: Lcom/schwager/KMLbuilder;
...

Thanks!
Re: Trying to get Eclipse + Tomcat + Groovy to work [message #227550 is a reply to message #227549] Sat, 07 February 2009 20:18 Go to previous messageGo to next message
Steve Whatmore is currently offline Steve WhatmoreFriend
Messages: 95
Registered: July 2009
Member
Check your Java Build Path on your project and make sure that your Groovy
JAR files are referenced there, otherwise Tomcat won't know about those
Groovy JAR files and you won't be able to reference them.

This is just an educated guess since I have not actually tried using Groovy
but it seems like this is most likely the problem.

"Mike Schwager" <groovy@schwager.com> wrote in message
news:aa6d07cafef040b1899d43d28f54d985$1@www.eclipse.org...
> Hi,
> I have created a Servlet using Eclipse J2EE version 3.4.1 and Tomcat 6.0.
> I also installed Groovy 1.5.7 and added the Grooviness to Eclipse, and
> added the Groovy nature to my project.
>
> I can create a Groovy or Java project and run a Groovy application in
> Eclipse. But I cannot run Groovy in a servlet.
>
> I created a small working servlet in Java. What I would like to do next
> is create a class in Groovy, then instantiate that class in my Java code.
> Like the following (in here, KMLbuilder is a very simple Groovy class).
> The question is, how can I get Groovy to work in a Tomcat Servlet, within
> the Eclipse development environment?
>
> public class Play extends HttpServlet {
> private static final long serialVersionUID = 1L;
> public KMLbuilder KMLbuilder;
> public Play() {
> super();
> }
>
> public void init(ServletConfig config) throws ServletException {
> KMLbuilder = new KMLbuilder();
> }
> ..
> }
> I get the following error in the Eclipse web browser when I try to execute
> this
> javax.servlet.ServletException: Error instantiating servlet class
> com.schwager.Play
> ..
> root cause
>
> java.lang.NoClassDefFoundError: Lcom/schwager/KMLbuilder;
> ..
>
> Thanks!
>
>
>
Re: Trying to get Eclipse + Tomcat + Groovy to work [message #227554 is a reply to message #227550] Mon, 09 February 2009 08:07 Go to previous messageGo to next message
Philippe Marschall is currently offline Philippe MarschallFriend
Messages: 121
Registered: July 2009
Senior Member
Whatty wrote:
> Check your Java Build Path

Java Build Path is only for compilation, Java EE Module Dependencies is
what gets deployed (and generates java.lang.NoClassDefFoundError).

Cheers
Philippe
Re: Trying to get Eclipse + Tomcat + Groovy to work [message #227576 is a reply to message #227554] Mon, 09 February 2009 23:14 Go to previous messageGo to next message
Mike Schwager is currently offline Mike SchwagerFriend
Messages: 3
Registered: July 2009
Junior Member
Thanks for the replies. I have checked the properties for my Project, and
under "Java EE Module Dependencies" I checked "Groovy Libraries". This
adds the Groovy libraries as a Web Library dependency, but does not help
with my Groovy class. I don't think my Class is still getting included in
the proper WEB-INF/lib directory at build. I am still getting (inside the
web browser; notice the spurious 'L'):

javax.servlet.ServletException: Error instantiating servlet class
com.schwager.Play
...
java.lang.NoClassDefFoundError: Lcom/schwager/KMLbuilder2;


And in my Console window, I am getting:

INFO: Marking servlet Play as unavailable
Feb 9, 2009 5:07:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Play
java.lang.ClassNotFoundException: com.schwager.KMLbuilder2

All I have in my "Play.java" file that might apply is:


import com.schwager.KMLbuilder2;

/**
* Servlet implementation class Play
*/
public class Play extends HttpServlet {
private static final long serialVersionUID = 1L;

public KMLbuilder2 KMLbuilder2;
...(more simple Java code follows, not germaine)...
Re: Trying to get Eclipse + Tomcat + Groovy to work [message #227578 is a reply to message #227576] Tue, 10 February 2009 07:53 Go to previous messageGo to next message
Philippe Marschall is currently offline Philippe MarschallFriend
Messages: 121
Registered: July 2009
Senior Member
Mike Schwager wrote:
> Thanks for the replies. I have checked the properties for my Project,
> and under "Java EE Module Dependencies" I checked "Groovy Libraries".
> This adds the Groovy libraries as a Web Library dependency, but does not
> help with my Groovy class.

Sure, it's very unlikely that Groovy Libraries includes a com.schwager
class. You also need to check the library that includes the
com.schwager.KMLbuilder2 class and all its dependencies.

> I don't think my Class is still getting
> included in the proper WEB-INF/lib directory at build. I am still
> getting (inside the web browser; notice the spurious 'L'):

That's fine, that's the the JNI type signature, that's also why there
are slashes instead of dots:
http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/ types.html#wp16432

Cheers
Philippe
Re: Trying to get Eclipse + Tomcat + Groovy to work [message #227604 is a reply to message #227578] Tue, 10 February 2009 21:25 Go to previous message
Mike Schwager is currently offline Mike SchwagerFriend
Messages: 3
Registered: July 2009
Junior Member
Sorry, I think there's some confusion here. I'm sure the Groovy Libraries
don't contain a com.schwager class (or package for that matter).

The KMLbuilder2.groovy file is being edited within the same source tree
(ie, the same package) as the Play.java file. That Groovy file is what
I'm trying to create right now.

When I edit files in Eclipse, I don't need to compile my .java files into
a jar and then include that jar in the build library set... my .java files
are exactly what I'm working on in Eclipse, and then the IDE is kind
enough to create the .class files and run my project when I ask it to.

I want to continue to do the same thing; however, it happens that I have a
file with a .groovy suffix, I've included the Groovy nature, I'm using the
Groovy syntax, and I am including the Groovy jar files. (In short, once
the .class files are created none of that should matter- it's just another
class but it got generated utilizing the Groovy nature).

So though I'm not working on the libraries, I need them in order to run,
natch. But what I AM working on and need help with are:
- Play.java - a standard Java class
- KMLbuilder2.groovy - a Groovy class.
Both of these files are in my Play(project)->src->com->schwager package.
"Play" instantiates an KMLbuilder2 object, which has but one method. The
whole KMLbuilder2 Groovy class looks like this:

package com.schwager
public class KMLbuilder2{
public String build () {
return '''
<html><body>Hello Jackson 5</html></body>
'''
}
}

It is called from a very simple java servlet, created in Eclipse, from
this method in Play.java:
(everything else in this class is boilerplate trivial Java servlet,
Eclipse-created code)
...
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
KMLbuilder2 KMLbuilder2=new KMLbuilder2();
byte[] result=KMLbuilder2.build().getBytes();
OutputStream output=response.getOutputStream();
output.write(result);
output.flush();
}
...


As it turns out, though, you got me going on the right path. I have
figured it out as I've typed this. What I needed to do was:

1. Go to my Project properties
2. Select "Java build path"
3. Observe the "Default output folder", which in my case is
"Play/build/classes"
4. Select "Groovy Project properties"
5. Change the "Groovy compiler output location" to be the same output
folder, minus the Project name. Thus for me, it would be "build/classes".

In this way, Eclipse puts all the .class files in the same directory.
Then when the servlet gets built, all the .class files I need are included.

Naturally, the groovy libraries need to be included (as you mentioned) in
the Java EE Module Dependencies.

Thanks again, I'm on the right track now I feel.
Previous Topic:API for new servers
Next Topic:Resource Not Available
Goto Forum:
  


Current Time: Tue Mar 19 11:45:10 GMT 2024

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

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

Back to the top