Skip to content

jgomer2001/grooving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

A small demonstration of Java scripting using the Groovy library.

Advantages:

  • Project maintenance guaranteed
  • Good docs
  • Small footprint ~8MB. Apparently no dependencies
  • Supports Java 8 syntax (probably 8+ too)
  • Easy to handle

Usage hints:

  • This is a maven project
  • Check class test
  • Uncomment lines in main method
  • See source files in resources directory

Some useful pointers:

About the "Integrating Groovy into applications" page:

GroovyScriptEngine is the way to go to in order to support scripts that depend on other scripts; also reloading is handled automatically. Plain GroovyClassLoader is fine when using a single standalone script. In this case reloading can be done by using parseClass.

A couple of lessons learned:

  • Dependant scripts must follow the convention of classes and directory naming of Java so they can be imported. As an example, class Hello of package there should be stored in a file named Hello.groovy inside There directory which should be under the root of the engine instance obtained. It does not have to be written in idiomatic Groovy, classic Java is OK.

  • The (main) script to run (via GroovyScriptEngine#run) can use the .java extension and does not need to follow the naming conventions. For practical purposes the script should return something, as in the example given in the doc page.

  • Both .groovy and .java extensions can be used for dependant scripts. However, this requires calling CompilerConfiguration#setScriptExtensions on the compiler configuration associated to the script engine. Otherwise, it will only work with .groovy files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published