Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Groovy/Java Integration

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

ciao
Dierk
 
reply
    Bookmark Topic Watch Topic
  • New Topic