Results 1 to 3 of 3
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Groovy Scripting and Java

    I am trying to implement groovy with my java app/game but I having a little trouble getting my head around the concept of scripting. Basically I want to employ scripting so that I can make changes to the content of my app without recompiling the entire app, thus also reducing the hassle of updating an app. However I don't really understand how to go about doing that. I have a groovy class setup in my project (this is in eclipse) but when I export it as an executable jar, the groovy class, which I still expected to be in a readable editable format, is now a .class file which is not readable/editable.

    So my question is, how do I go about exporting my project so that all my scripts remain editable after compilation?

    How do I interface my java code with groovy and vis versa?

    I am using Eclipse indigo and the Groovy eclipse plugin, would really appreciate a little background on the concepts of scripting.

    Thanks in advance!

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Rep Power

    Default Re: Groovy Scripting and Java

    Because they are run via the JVM, groovy scripts must be compiled into binary. To avoid direct compilation every time you change the script, pass the script to the groovy application which will deal with the compilation step for you

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default Re: Groovy Scripting and Java

    I could be wrong, but I thought you could just create a new GroovyShell in your java app, and pass it the groovy script as a string. Page 178 of "Pragmatic Bookshelf; Programming Groovy April 2008 by Venkat Subramaniam" has an example.

    For your reference:
    Java Code:
    // Java code
    package com.agiledeveloper; import javax.script.*;
    public class CallingScript {
        public static void main(String[] args) {
            ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("groovy");     
            System.out.println("Calling script from Java");
                engine.eval("println 'Hello from Groovy'");
            }catch(ScriptException ex) {

Similar Threads

  1. JAVA scripting
    By conker5295 in forum New To Java
    Replies: 9
    Last Post: 02-22-2012, 07:49 AM
  2. Replies: 0
    Last Post: 01-12-2012, 10:46 AM
  3. Java & shell scripting
    By kswapnadevi in forum Advanced Java
    Replies: 12
    Last Post: 11-21-2010, 06:41 AM
  4. P~ 0.9 : Java-friendly scripting with powerful regex
    By p7eregex in forum Java Software
    Replies: 0
    Last Post: 12-17-2007, 08:10 PM
  5. Replies: 0
    Last Post: 05-24-2007, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts