3

I have a Java application that does something like:

public class MyApplication {
    public static int main(String[] args) {
      System.out.println(System.getProperty("my.property"));
    }
}

How do I call this from Groovy such that the Groovy script sets the System property?

2 Answers 2

6

You can call Java with the -D command line parameter:

def output = "java -Dmy.property=foo MyApplication".execute().text

Alternatively, you can call the Java class from within your script without starting a new Java process:

System.properties['my.property'] = 'foo'
MyApplication.main([] as String[])
Sign up to request clarification or add additional context in comments.

Comments

0

I have a java application in eclipse IDE. IDE is installed with groovy plugin. To run this java application in groovy, just right click the application run as --> Groovy Console. It will execute the application in groovy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.