DurchflusstabelleFactory - GroovyClassLoader-Demo

Date Submitted Sun. Mar. 4th, 2007 12:48 PM
Revision 1 of 1
Helper BerndSchiffer
Tags groovy | groovyclassloader | Java
Comments 0 comments
A GroovyClassLoader demonstration. The given domain is a german water flow meter system; I think, you shouldn't be able to understand the domain, but you should be able to understand, how to load a Groovy class in Java via a GroovyClassLoader.

import groovy.lang.GroovyClassLoader;

public class DurchflusstabelleFactory

  private static final String DURCHFLUSSTABELLE_GROOVY = "durchflusstabelle.groovy";

  public static Durchflusstabelle createDurchflusstabelle()
    Class clazz = DurchflusstabelleFactory.class;
    ClassLoader parent = clazz.getClassLoader();
    GroovyClassLoader loader = new GroovyClassLoader(parent);
    Class groovyClass = loader.parseClass(clazz.getResourceAsStream(DURCHFLUSSTABELLE_GROOVY));
      return (Durchflusstabelle) groovyClass.newInstance();
    catch (Exception programmierfehler)
      throw new RuntimeException("Konnte Klasse " +
          DURCHFLUSSTABELLE_GROOVY + " nicht laden!",


There are currently no comments for this snippet.


Votes Down

Helper fastmike
Helper lolfejs