File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes Groovy/Java Integration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Groovy/Java Integration" Watch "Groovy/Java Integration" New topic

Groovy/Java Integration

Eric Martinez

Joined: Nov 20, 2005
Posts: 25
Hi, I got a few quick questions..

If you create a class in Java can the class be instantiated and then used in Groovy? If so, then can a Java class see or manipulate a Groovy object's members?
Edward Povazan

Joined: Dec 12, 2006
Posts: 3
You can use Groovy classes from Java and Java classes from Groovy.
This forum has 'scripting' in its topic, but that is one part of Groovy. You can use Groovy to create classes instead of Java, when appropriate. And of course, you need the groovy jar in your classpath.
Dierk König
Ranch Hand

Joined: Nov 01, 2006
Posts: 43
Using a Java class from Groovy is exactly like using a Java class from Java. There is no difference. It's fully transparent.

Using a Groovy class from Java requires you to either
- groovyc your Groovy class and put the resulting class files on the classpath
- or use one of the several integration mechanisms
- Eval, GroovyShell, GroovyScriptEngine, GroovyClassLoader
- BSF or JSR-223
- Spring

The several mechanisms are there to provide support the simplest cases of evaluating a simple string of Groovy code up to the point where you have Groovy classes delivered transparently through the class loader.

I agree. Here's the link:
subject: Groovy/Java Integration
It's not a secret anymore!