{"id":858,"date":"2009-11-21T19:28:04","date_gmt":"2009-11-22T04:28:04","guid":{"rendered":"https:\/\/www.kellyrob99.com\/blog\/?p=858"},"modified":"2009-11-21T19:28:04","modified_gmt":"2009-11-22T04:28:04","slug":"different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier","status":"publish","type":"post","link":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/","title":{"rendered":"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;"},"content":{"rendered":"<p>Lately I&#8217;ve been thinking about all the different ways to bring Groovy into a pure Java or command line environment, and ended up diving into some code to explore the various options.  Turns out there&#8217;s definitely a good variety of options for running Groovy dynamically inside and out of a Java application. I started out on <a href=\"http:\/\/groovy.codehaus.org\/Embedding+Groovy\">this page from the Groovy site<\/a>.<br \/>\nIn particular for the environments I&#8217;ve been working in lately it&#8217;s been important to be able to run the same code both from within a Java application and from the command line. It&#8217;s also been a &#8216;nice to have&#8217; to be able to package a jar with a bunch of the same scripts compiled together. Using maven as a harness also has the benefit of allowing for testing compiled scripts directly through instantiation even though the intended usage is from within a Java app using one of these methods. Source code is <a href=\"http:\/\/github.com\/kellyrob99\/running-groovy\">available here on github<\/a>.<\/p>\n<p><\/p>\n<h3>Groovy on the command line<\/h3>\n<p>The quickest and simplest way to run a Groovy Script or Class, command line arguments are automatically marshalled into an &#8216;args&#8217; String array. Please note that due to a problem I&#8217;m having with my syntax highlighter plugin the process execution is shown here in single quotes; the actual code requires a GString(double quoted) in order to do the replacement for the inline variable. <code>&amp;quot;<\/code> THAT WordPress!<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\n\/\/the script\r\nmyArgs = args\r\nresult = args.join(' ')\r\nprintln result\r\nprintln myArgs\r\n\r\n\/\/...and the test\r\n    void testGroovyCall()\r\n    {\r\n        def proc = 'groovy $groovyScriptOne Hello World'.execute()\r\n        proc.waitFor()\r\n        def result = proc.text.split()\r\n        assert result&#x5B;0] == 'Hello'\r\n        assert result&#x5B;1] == 'World'\r\n    }\r\n\r\n<\/pre>\n<p><\/p>\n<h3>GroovyShell<\/h3>\n<p>This is the basis of Groovy script execution. The <a href=\"http:\/\/groovy.codehaus.org\/api\/groovy\/lang\/GroovyShell.html\">GroovyShell<\/a> allows for executing scripts, passing in a particular Binding context that allows for bi-directional communication between the script and the calling code. Parameters can be passed into the executing script in the Binding and results can be stored there to be returned to the calling context. GroovyShell also allows for running a class from the &#8216;main&#8217; method, passing in String arguments. It will also execute implementers of Runnable and test files for  JUnit or TestNG. Script text can also be declared inline and executed in the same way as files on disk. All in all, pretty bloody handy. Here&#8217;s a straightforward example of running a dirt simple Groovy script and inspecting the results. Note that this isn&#8217;t executable as shown, but I&#8217;ll provide the full source code on github for anyone who wants a closer look. Note that I&#8217;m also passing in an &#8216;out&#8217; variable in the Binding, which effectively redirect System.out to a specified Writer implementation &#8211; a nice touch for inspecting output.<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\n\/\/the script\r\nmyArgs = args\r\nresult = args.join(' ')\r\nprintln result\r\nprintln myArgs\r\n\r\n \/\/...and the test\r\n    void testGroovyShell()\r\n    {\r\n        Binding binding = helper.createBinding()\r\n        def shell = new GroovyShell(binding)\r\n        shell.evaluate(new File(groovyScriptOne))\r\n        helper.assertBinding(binding)\r\n    }\r\n\r\n\/\/...and the Binding creation\/assertion\r\n     def static args = &#x5B;'Hello', 'World'].asImmutable()\r\n     \/**\r\n     * Create a Binding with a single parameter to be passed to scripts and an 'out' Writer to redirect console output.\r\n     *\/\r\n    private Binding createBinding()\r\n    {\r\n        Binding binding = new Binding()\r\n        def sWriter = new StringWriter()\r\n        def pWriter = new PrintWriter(sWriter)\r\n        binding.setVariable ('args', new ArrayList(args))\r\n        binding.setVariable ('out', pWriter)\r\n        return binding\r\n    }\r\n\r\n    \/**\r\n     * Assert that the expected 'common' actions are done with the Binding by each of the use cases.\r\n     * The original 'args' should be as expected.\r\n     * A copy of 'args' should have been placed in the Binding during execution.\r\n     * The 'result' should be the concatentation of 'args' separated by spaces.\r\n     *\/\r\n    private def assertBinding(Binding binding)\r\n    {\r\n        assert binding.variables.size() == 4\r\n        assert binding.variables.args.value&#x5B;0].toString() == args&#x5B;0]\r\n        assert binding.variables.args.value&#x5B;1].toString() == args&#x5B;1]\r\n        assert binding.variables.result.value.toString() == args.join(' ')\r\n        assert binding.variables.myArgs.value&#x5B;0].toString() == args&#x5B;0]\r\n        assert binding.variables.myArgs.value&#x5B;1].toString() == args&#x5B;1]\r\n    }\r\n<\/pre>\n<p><\/p>\n<h3>GroovyScriptEngine<\/h3>\n<p>The <a href=\"http:\/\/groovy.codehaus.org\/api\/groovy\/util\/GroovyScriptEngine.html\">GroovyScriptEngine<\/a> enables dynamically running Groovy sources located in a fixed set of content roots,  complete with reloading modified scripts in between executions. Running a Groovy script this way is essentially the same as using GroovyShell.<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\n    void testGroovyScriptEngine()\r\n    {\r\n        Binding binding = helper.createBinding()\r\n        def gse = new GroovyScriptEngine(new File('.').toURL())\r\n        gse.run(groovyScriptOne, binding)\r\n        helper.assertBinding(binding)\r\n    }\r\n<\/pre>\n<p><\/p>\n<h3>GroovyClassLoader<\/h3>\n<p>An extension to URLClassLoader that enables parsing Groovy sources into Class representations. Once a Class object is created, instances of the class can be created easily and either cast to a known type or manipulated through convention by use of the standard Groovy &#8216;invokeMethod&#8217;.  This works equally well on Groovy and Java btw. Here&#8217;s an example of running a Java class using <a href=\"http:\/\/groovy.codehaus.org\/api\/groovy\/lang\/GroovyClassLoader.html\">GroovyClassLoader<\/a>. In this case the Java file has a field called &#8216;binding&#8217; and implements a &#8216;run&#8217; method.<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\n    \/**\r\n     * Dynamically compile, instantiate, inspect and call methods on a POJO.\r\n     *\/\r\n    void testGroovyClassLoaderOnJava()\r\n    {\r\n        GroovyClassLoader loader = new GroovyClassLoader();\r\n        Class javaClass = loader.parseClass(new File(javaFileOne));\r\n\r\n        def groovyObject = javaClass.newInstance();\r\n        def binding = helper.createBinding()\r\n        groovyObject.binding = binding\r\n        if(groovyObject.metaClass.respondsTo(groovyObject, 'run'))\r\n        {\r\n            groovyObject.invokeMethod('run', null);\r\n            helper.assertBinding(binding)\r\n        }\r\n        if(groovyObject.metaClass.respondsTo(groovyObject, 'main'))\r\n        {\r\n            groovyObject.invokeMethod('main', new ArrayList(helper.args) as String&#x5B;]);\r\n        }\r\n    }\r\n<\/pre>\n<p><\/p>\n<h3>(Groovy)Console<\/h3>\n<p>The <a href=\"http:\/\/groovy.codehaus.org\/gapi\/groovy\/ui\/Console.html\">Console<\/a> can be embedded in Java or Groovy code to provide a dynamic interactive Swing environment. This is the same UI spawned from the command line invocation of &#8216;groovyConsole&#8217;. Internally it uses GroovyShell for actual execution, and so can do everything that GroovyShell can do &#8211; plus a couple of additions. For one, you can add jars and\/or directories to the classpath used when executing your scripts.<br \/>\n<a href=\"https:\/\/www.kellyrob99.com\/blog\/?attachment_id=885\" rel=\"attachment wp-att-885\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.kellyrob99.com\/blog\/wp-content\/uploads\/2009\/11\/Picture-6.png?resize=651%2C457&#038;ssl=1\" alt=\"Groovy Console\" title=\"Groovy Console\" class=\"size-full wp-image-885\" width=\"651\" height=\"457\" srcset=\"https:\/\/i0.wp.com\/www.kellyrob99.com\/blog\/wp-content\/uploads\/2009\/11\/Picture-6.png?w=651&amp;ssl=1 651w, https:\/\/i0.wp.com\/www.kellyrob99.com\/blog\/wp-content\/uploads\/2009\/11\/Picture-6.png?resize=300%2C210&amp;ssl=1 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/a><\/p>\n<p><\/p>\n<h3>The Best of Both Worlds &#8211; at Least for my use case<\/h3>\n<p>In actual practice these patterns can be used a lot more successfully by observing standard Java practices, like casting classes parsed using GroovyClassLoader to a known interface before interacting with them, or by using Classes to organize business logic inside of a Script that essentially functions as a &#8216;main&#8217; method.  This example defines two dependent internal classes, marshals parameters to them and then returns the results attached to the originally passed in Binding.<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\n\/**\r\n * Classes inside of a Script.\r\n *\/\r\nclass TestableClass\r\n{\r\n    Binding binding\r\n\r\n    def run()\r\n    {\r\n        binding.with\r\n        {\r\n            setVariable('myArgs', getVariable('args'))\r\n            setVariable('result', getVariable('args')?.join(' '))\r\n        }\r\n        return binding\r\n    }\r\n}\r\n\r\nclass TestableClass2\r\n{\r\n    Binding binding\r\n\r\n    public TestableClass2(Binding binding)\r\n    {\r\n        this.binding = binding;\r\n    }\r\n\r\n    def run()\r\n    {\r\n        return new TestableClass(binding: binding).run()\r\n    }\r\n}\r\n\r\nif (args)\r\n{\r\n    def internalBinding = new Binding()\r\n    internalBinding.setVariable('args', new ArrayList(args))\r\n    internalBinding = new TestableClass2(internalBinding).run()\r\n    args = internalBinding.args\r\n    myArgs = internalBinding.myArgs\r\n    result = internalBinding.result  \/\/return value from script\r\n}\r\nelse\r\n{\r\n    println 'no args!!'\r\n}\r\n<\/pre>\n[table \u201c1\u201d not found \/]<br \/>\n\n<div class=\"zemanta-pixie\"><a class=\"zemanta-pixie-a\" href=\"http:\/\/reblog.zemanta.com\/zemified\/8cba1f46-7f81-473a-8fe0-ce5f0a45ec40\/\" title=\"Reblog this post [with Zemanta]\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"zemanta-pixie-img\" src=\"https:\/\/i0.wp.com\/img.zemanta.com\/reblog_c.png\" alt=\"Reblog this post [with Zemanta]\" \/><\/a><span class=\"zem-script more-related pretty-attribution\"><script type=\"text\/javascript\" src=\"http:\/\/static.zemanta.com\/readside\/loader.js\" defer=\"defer\"><\/script><\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve been thinking about all the different ways to bring Groovy into a pure Java or command line environment, and ended up diving into some code to explore the various options. Turns out there&#8217;s definitely a good variety of options for running Groovy dynamically inside and out of a Java application. I started out [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[6],"tags":[153,155,154,257,152,150,151,149,258,35,132,148,113],"class_list":["post-858","post","type-post","status-publish","format-standard","hentry","category-dev","tag-console","tag-dynamic-execution","tag-embedded","tag-groovy","tag-groovyconsole","tag-groovyscriptengine","tag-groovyshell","tag-hello-world-program","tag-java","tag-programming","tag-script","tag-source-code","tag-thekaptain"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"TheKaptain\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"The Kaptain on ... stuff | Tales of development, life and the folly that goes along with both\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Different Flavors of Embedded Groovy in Java Apps or &quot;How To Make your Java Groovier!&quot; | The Kaptain on ... stuff\" \/>\n\t\t<meta property=\"og:description\" content=\"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2009-11-22T04:28:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-11-22T04:28:04+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Different Flavors of Embedded Groovy in Java Apps or &quot;How To Make your Java Groovier!&quot; | The Kaptain on ... stuff\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#article\",\"name\":\"Different Flavors of Embedded Groovy in Java Apps or \\\"How To Make your Java Groovier!\\\" | The Kaptain on ... stuff\",\"headline\":\"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;\",\"author\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.kellyrob99.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/11\\\/Picture-6.png?fit=651%2C457&ssl=1\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#articleImage\",\"width\":651,\"height\":457,\"caption\":\"Groovy Console\"},\"datePublished\":\"2009-11-21T19:28:04-09:00\",\"dateModified\":\"2009-11-21T19:28:04-09:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#webpage\"},\"articleSection\":\"Development, Console, dynamic execution, embedded, Groovy, groovyConsole, GroovyScriptEngine, GroovyShell, Hello world program, Java, Programming, script, Source code, theKaptain\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/category\\\/dev\\\/#listItem\",\"name\":\"Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/category\\\/dev\\\/#listItem\",\"position\":2,\"name\":\"Development\",\"item\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/category\\\/dev\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#listItem\",\"name\":\"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#listItem\",\"position\":3,\"name\":\"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/category\\\/dev\\\/#listItem\",\"name\":\"Development\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/#organization\",\"name\":\"The Kaptain on ... stuff\",\"description\":\"Tales of development, life and the folly that goes along with both\",\"url\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"TheKaptain\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e41f09f3548f065fe6967ac904d3ea2a638614c16d879cac47cfad64e5b1426a?s=96&d=monsterid&r=g\",\"width\":96,\"height\":96,\"caption\":\"TheKaptain\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#webpage\",\"url\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/\",\"name\":\"Different Flavors of Embedded Groovy in Java Apps or \\\"How To Make your Java Groovier!\\\" | The Kaptain on ... stuff\",\"description\":\"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/2009\\\/11\\\/21\\\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2009-11-21T19:28:04-09:00\",\"dateModified\":\"2009-11-21T19:28:04-09:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/\",\"name\":\"The Kaptain on ... stuff\",\"description\":\"Tales of development, life and the folly that goes along with both\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.kellyrob99.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Different Flavors of Embedded Groovy in Java Apps or \"How To Make your Java Groovier!\" | The Kaptain on ... stuff","description":"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.","canonical_url":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#article","name":"Different Flavors of Embedded Groovy in Java Apps or \"How To Make your Java Groovier!\" | The Kaptain on ... stuff","headline":"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;","author":{"@id":"https:\/\/www.kellyrob99.com\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/www.kellyrob99.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.kellyrob99.com\/blog\/wp-content\/uploads\/2009\/11\/Picture-6.png?fit=651%2C457&ssl=1","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#articleImage","width":651,"height":457,"caption":"Groovy Console"},"datePublished":"2009-11-21T19:28:04-09:00","dateModified":"2009-11-21T19:28:04-09:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#webpage"},"isPartOf":{"@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#webpage"},"articleSection":"Development, Console, dynamic execution, embedded, Groovy, groovyConsole, GroovyScriptEngine, GroovyShell, Hello world program, Java, Programming, script, Source code, theKaptain"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.kellyrob99.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/#listItem","name":"Development"}},{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/#listItem","position":2,"name":"Development","item":"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#listItem","name":"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#listItem","position":3,"name":"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;","previousItem":{"@type":"ListItem","@id":"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/#listItem","name":"Development"}}]},{"@type":"Organization","@id":"https:\/\/www.kellyrob99.com\/blog\/#organization","name":"The Kaptain on ... stuff","description":"Tales of development, life and the folly that goes along with both","url":"https:\/\/www.kellyrob99.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.kellyrob99.com\/blog\/author\/admin\/#author","url":"https:\/\/www.kellyrob99.com\/blog\/author\/admin\/","name":"TheKaptain","image":{"@type":"ImageObject","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/e41f09f3548f065fe6967ac904d3ea2a638614c16d879cac47cfad64e5b1426a?s=96&d=monsterid&r=g","width":96,"height":96,"caption":"TheKaptain"}},{"@type":"WebPage","@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#webpage","url":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/","name":"Different Flavors of Embedded Groovy in Java Apps or \"How To Make your Java Groovier!\" | The Kaptain on ... stuff","description":"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.kellyrob99.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/#breadcrumblist"},"author":{"@id":"https:\/\/www.kellyrob99.com\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/www.kellyrob99.com\/blog\/author\/admin\/#author"},"datePublished":"2009-11-21T19:28:04-09:00","dateModified":"2009-11-21T19:28:04-09:00"},{"@type":"WebSite","@id":"https:\/\/www.kellyrob99.com\/blog\/#website","url":"https:\/\/www.kellyrob99.com\/blog\/","name":"The Kaptain on ... stuff","description":"Tales of development, life and the folly that goes along with both","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.kellyrob99.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"The Kaptain on ... stuff | Tales of development, life and the folly that goes along with both","og:type":"article","og:title":"Different Flavors of Embedded Groovy in Java Apps or &quot;How To Make your Java Groovier!&quot; | The Kaptain on ... stuff","og:description":"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.","og:url":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/","article:published_time":"2009-11-22T04:28:04+00:00","article:modified_time":"2009-11-22T04:28:04+00:00","twitter:card":"summary","twitter:title":"Different Flavors of Embedded Groovy in Java Apps or &quot;How To Make your Java Groovier!&quot; | The Kaptain on ... stuff","twitter:description":"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment."},"aioseo_meta_data":{"post_id":"858","title":"Different Flavors of Embedded Groovy in Java Apps or &quot;How To Make your Java Groovier!&quot; | #site_title","description":"Demonstration of a few of the different ways to dynamically invoke Groovy code within a Java environment.","keywords":[{"label":"Programming","value":"Programming"},{"label":"Groovy","value":"Groovy"},{"label":"Source code","value":"Source code"},{"label":"Hello world program","value":"Hello world program"},{"label":"GroovyScriptEngine","value":"GroovyScriptEngine"},{"label":"GroovyShell","value":"GroovyShell"},{"label":"groovyConsole","value":"groovyConsole"},{"label":"Console","value":"Console"},{"label":"Script","value":"Script"},{"label":"TheKaptain","value":"TheKaptain"},{"label":"embedded","value":"embedded"},{"label":"dynamic execution","value":"dynamic execution"},{"label":"Java","value":"Java"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-02-09 05:15:21","updated":"2025-11-29 20:26:59","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.kellyrob99.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDifferent Flavors of Embedded Groovy in Java Apps or \u201cHow To Make your Java Groovier!\u201d\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.kellyrob99.com\/blog"},{"label":"Development","link":"https:\/\/www.kellyrob99.com\/blog\/category\/dev\/"},{"label":"Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;","link":"https:\/\/www.kellyrob99.com\/blog\/2009\/11\/21\/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier\/"}],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/prjtg-dQ","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/posts\/858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/comments?post=858"}],"version-history":[{"count":96,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/posts\/858\/revisions"}],"predecessor-version":[{"id":955,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/posts\/858\/revisions\/955"}],"wp:attachment":[{"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/media?parent=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/categories?post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kellyrob99.com\/blog\/wp-json\/wp\/v2\/tags?post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}