Question

I'd like to do some import of my own classes for use inside DSLD script, but DSLD compilation does not seem to use project's classpath - import statements break the compilation, and Class.forName throws class not found exception. Is there a way to put custom jars on DSLD classpath, so I can use my own classes inside conribution blocks? I am using Eclipse 3.7 and latest groovy plugin (2.6.0)

No correct solution

OTHER TIPS

You can just pass a string with the fully qualified class name and as long as its on the projects classpath where the DSLD is being evaluated then it will work. This is described here groovy-eclipse DSLDs

Some subtleties about java.lang.Class references

Even though the DSLD script is being edited in the context of your project, the script is actually loaded by Groovy-Eclipse. And so, the runtime classpath of the script corresponds to Groovy-Eclipse's classpath, rather than the classpath of your project.

Consequently, you cannot reference class objects for types defined in your project. However, you can reference class objects that are available to Groovy-Eclipse. This might be confusing since the compiler will not show compile errors when types defined in your project are referenced as class objects, but it will show compile errors when Groovy-Eclipse types are referenced. This is because the Groovy-Eclipse compiler works off of the project's classpath. It is not yet aware that DSLD files will be run with a different classpath.

More specifically:

Instead of referencing the class MyLocalType directly, you can reference it as a String "com.mycompany.MyLocalType" Standard JDK, GDK, and all types defined in groovy-all are available directly in your DSLD and will show compile errors. It is possible to reference types in packages beginning with org.eclipse.jdt. and org.codehaus.groovy.eclipse. if all references are fully qualified. However, this is not recommended unless you really know what you are doing.

I don't know much about the DSLD stuff, but it looks like Groovy might have it's own means of doing that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top