Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Embedding Groovy

Embedding Groovy Groovy has been designed to be very lightweight and easy to embed into any Java application or system. BSF to embed any scripting language into your Java code; however Groovy offers a lighter weight and closer integration. There are

Tutorial Details:

the GroovyClassLoader to load classes dynamically into a Java program and execute them directly. The following Java code shows an example...


ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(new File(\"src/test/groovy/script/HelloWorld.groovy\"));// lets call some method on an instance
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
Object[] args = {};
groovyObject.invokeMethod(\"run\", args);

GroovyClassLoader gcl = new GroovyClassLoader();
Class clazz = gcl.parseClass(myStringwithGroovyClassSource \"SomeName.groovy\");
Object aScript = clazz.newInstance();
MyInterface myObject = (MyInterface) aScript;
myObject.interfaceMethod();
...
This works fine if the Groovy class implements the inferface MyInterface. myObject can from then on be used as every other Java object implementing MyInterface.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Embedding Groovy

View Tutorial:
Embedding Groovy

Related Tutorials:

Integrating Databases
Integrating Databases
 
SQLJ: The 'open sesame' of Java database applications
SQLJ: The 'open sesame' of Java database applications
 
An instrumentation network for weather data on the Web
An instrumentation network for weather data on the Web
 
Scripting power saves the day for your Java apps
Scripting power saves the day for your Java apps
 
Solve your servlet-based presentation problems - JavaWorld November 2000
Solve your servlet-based presentation problems - JavaWorld November 2000
 
Tcl your Java apps - JavaWorld March 2001
Tcl your Java apps - JavaWorld March 2001
 
Boost Struts with
Boost Struts with XSLT and XML
 
Customized EJB security in JBoss
Customized EJB security in JBoss
 
Test networked code the easy way
Test networked code the easy way
 
Maybe the future UI design of choice
Maybe the future UI design of choice
 
Excelling in Excel with Java
Excelling in Excel with Java
 
Sphinx-4 - A speech recognizer
Sphinx-4 - A speech recognizer General Information about Sphinx-4 Introduction Sphinx-4 is a state-of-the-art speech recognition system written entirely in the JavaTM programming language. It was created via a joint collaboration between the Sphinx
 
Getting Groovy with XML
XML sucks. Oh, wait, XML rocks. Well, it actually does a lot of both. It rocks because of all of the editors, validators, and tools written for it. XML has all but replaced any notion of a new custom text-based data language. But it also sucks because it\
 
alt.lang.jre: Take a shine to JRuby
JRuby combines the object-oriented strength of Smalltalk, the expressiveness of Perl, and the flexibility of the Java class libraries into a single, efficient rapid development framework for the Java platform. In this third installment in the alt.lang.jre
 
Groovy, Java\'s New Scripting Language
Groovy, Java\'s New Scripting Language When some Java developers hear about Groovy, their first reaction often is, as mine was, "Oh, no, not another scripting language for Java." We already have, after all, JavaScript and Rhino, Jython, Jelly, BeanShell,
 
Build scripts with Groovy and Ant
Build scripts with Groovy and Ant Summary In nearly all developers' toolboxes, Ant is the standard build tool for Java applications, thanks to its open, standard, and multiplatform structure. Though it represents a great improvement in automating produc
 
Using the ASM Toolkit for Bytecode Manipulation
Using the ASM Toolkit for Bytecode Manipulation Sometimes Java developers need to generate or change Java bytecode in the runtime. Is can be necessary for AOP or debugging, or even for performance optimization. There are several frameworks available that
 
Practically Groovy: Unit test your Java code faster with Groovy
Why unit test with Groovy? What makes Groovy particularly appealing with respect to other scripting platforms is its seamless integration with the Java platform. Because it's based on the Java language (unlike other alternate languages for the JRE, which
 
Practically Groovy: JDBC programming with Groovy
Take your practical knowledge of Groovy one step further this month, as Andrew Glover shows you how to use GroovySql to build a simple data-reporting application. GroovySql combines closures and iterators to ease Java Database Connectivity (JDBC) programm
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.