From 7c3082a0930e7937c0507021fc0ca6a2d25e1d0a Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Fri, 24 May 2019 08:09:59 +0100 Subject: [PATCH 1/8] BAEL-2899: project structure and example classes --- java-groovy-joint/pom.xml | 132 ++++++++++++++++++ .../main/groovy/com.baeldung/CalcMath.groovy | 19 +++ .../groovy/com.baeldung/CalcScript.groovy | 19 +++ .../src/main/java/com/baeldung/App.java | 54 +++++++ 4 files changed, 224 insertions(+) create mode 100644 java-groovy-joint/pom.xml create mode 100644 java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy create mode 100644 java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy create mode 100644 java-groovy-joint/src/main/java/com/baeldung/App.java diff --git a/java-groovy-joint/pom.xml b/java-groovy-joint/pom.xml new file mode 100644 index 0000000000..67365cf999 --- /dev/null +++ b/java-groovy-joint/pom.xml @@ -0,0 +1,132 @@ + + + + 4.0.0 + java-groovy-joint + 0.1.0-SNAPSHOT + java-groovy-joint + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + UTF-8 + 3.9 + 1.8 + 3.8.1 + 1.2.3 + 2.5.7 + + + + + bintray + Groovy Bintray + https://dl.bintray.com/groovy/maven + + never + + + false + + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + org.codehaus.groovy + groovy-all + ${groovy.version} + pom + + + junit + junit + 4.11 + test + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + com.baeldung.App + true + + + + + + maven-compiler-plugin + 3.8.0 + + groovy-eclipse-compiler + ${java.version} + ${java.version} + + + + org.codehaus.groovy + groovy-eclipse-compiler + 3.3.0-01 + + + org.codehaus.groovy + groovy-eclipse-batch + ${groovy.version}-01 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + + jar-with-dependencies + + + + + com.baeldung.App + + + + + + + make-assembly + + package + + single + + + + + + + + + diff --git a/java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy b/java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy new file mode 100644 index 0000000000..d9709653c7 --- /dev/null +++ b/java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy @@ -0,0 +1,19 @@ +package com.baeldung + +import org.slf4j.LoggerFactory + +class CalcMath { + def log = LoggerFactory.getLogger(this.getClass()) + + def calcSum(x, y) { + log.info "Executing $x + $y" + x + y + } + + def calcSum2(x, y) { + log.info "Executing $x + $y" + // DANGER! This won't throw a compilation issue and fail only at runtime!!! + calcSum3() + log.info("Logging an undefined variable: $z") + } +} \ No newline at end of file diff --git a/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy b/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy new file mode 100644 index 0000000000..2278f0dab8 --- /dev/null +++ b/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy @@ -0,0 +1,19 @@ +package com.baeldung + +import org.slf4j.LoggerFactory + +abstract class CalcScript extends Script { + def log = LoggerFactory.getLogger(this.getClass()) + + def calcSum(x, y) { + log.info "Executing $x + $y" + x + y + } + + def calcSum2(x, y) { + log.info "Executing $x + $y" + // DANGER! This won't throw a compilation issue and fail only at runtime!!! + calcSum3() + log.info("Logging an undefined variable: $z") + } +} \ No newline at end of file diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/java-groovy-joint/src/main/java/com/baeldung/App.java new file mode 100644 index 0000000000..0a201d12e2 --- /dev/null +++ b/java-groovy-joint/src/main/java/com/baeldung/App.java @@ -0,0 +1,54 @@ +package com.baeldung; + +import groovy.lang.Binding; +import groovy.lang.GroovyClassLoader; +import groovy.lang.GroovyShell; +import org.codehaus.groovy.control.CompilerConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Hello world! + * + */ +public class App { + private final static Logger LOG = LoggerFactory.getLogger(App.class); + private final GroovyClassLoader loader; + private final GroovyShell shell; + + private App() { + loader = new GroovyClassLoader(this.getClass().getClassLoader()); + CompilerConfiguration config = new CompilerConfiguration(); + config.setScriptBaseClass("com.baeldung.CalcScript"); + shell = new GroovyShell(loader, new Binding(), config); + } + + private void runScript(int x, int y) { + Object script = shell.parse(String.format("calcSum(%d,%d)", x, y)); + assert script instanceof CalcScript; + Object result = ((CalcScript) script).run(); + LOG.info("Result of run() method is {}", result); + + Object script2 = shell.parse("CalcScript"); + Object result2 = ((CalcScript) script2).calcSum(x + 7, y + 7); + LOG.info("Result of calcSum() method is {}", result2); + + } + + private void runClass(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + Class calcClass = loader.loadClass("com.baeldung.CalcMath"); + Object calc = calcClass.newInstance(); + assert calc instanceof CalcMath; + + Object result = ((CalcMath) calc).calcSum(x, y); + LOG.info("Result is {}", result); + } + + public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException { + App app = new App(); + LOG.info("Running a groovy script..."); + app.runScript(5, 10); + LOG.info("Running a groovy class..."); + app.runClass(1, 3); + } +} From 653717e25ef14bf7aadaed736d268fb9fe4a371c Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Sun, 26 May 2019 01:09:20 +0100 Subject: [PATCH 2/8] BAEL-2899: adding some more case scenarios --- java-groovy-joint/gmavenplus-pom.xml | 148 ++++++++++++++++++ java-groovy-joint/pom.xml | 1 + .../groovy/com.baeldung/CalcScript.groovy | 19 --- .../baeldung}/CalcMath.groovy | 6 + .../groovy/com/baeldung/CalcScript.groovy | 10 ++ .../src/main/java/com/baeldung/App.java | 74 +++++++-- 6 files changed, 228 insertions(+), 30 deletions(-) create mode 100644 java-groovy-joint/gmavenplus-pom.xml delete mode 100644 java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy rename java-groovy-joint/src/main/groovy/{com.baeldung => com/baeldung}/CalcMath.groovy (76%) create mode 100644 java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy diff --git a/java-groovy-joint/gmavenplus-pom.xml b/java-groovy-joint/gmavenplus-pom.xml new file mode 100644 index 0000000000..b34eeb292d --- /dev/null +++ b/java-groovy-joint/gmavenplus-pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + java-groovy-joint + 0.1.0-SNAPSHOT + java-groovy-joint + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + UTF-8 + 3.9 + 1.8 + 3.8.1 + 1.2.3 + 2.5.7 + + + + + bintray + Groovy Bintray + https://dl.bintray.com/groovy/maven + + never + + + false + + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + org.codehaus.groovy + groovy-all + ${groovy.version} + pom + + + junit + junit + 4.11 + test + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + com.baeldung.App + true + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + 1.7.0 + + + + execute + addSources + addTestSources + generateStubs + compile + generateTestStubs + compileTests + removeStubs + removeTestStubs + + + + + + org.codehaus.groovy + groovy-all + + 2.5.6 + runtime + pom + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + + jar-with-dependencies + + + + + com.baeldung.App + + + + + + + make-assembly + + package + + single + + + + + + + + + diff --git a/java-groovy-joint/pom.xml b/java-groovy-joint/pom.xml index 67365cf999..5ac4768865 100644 --- a/java-groovy-joint/pom.xml +++ b/java-groovy-joint/pom.xml @@ -27,6 +27,7 @@ Groovy Bintray https://dl.bintray.com/groovy/maven + never diff --git a/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy b/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy deleted file mode 100644 index 2278f0dab8..0000000000 --- a/java-groovy-joint/src/main/groovy/com.baeldung/CalcScript.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung - -import org.slf4j.LoggerFactory - -abstract class CalcScript extends Script { - def log = LoggerFactory.getLogger(this.getClass()) - - def calcSum(x, y) { - log.info "Executing $x + $y" - x + y - } - - def calcSum2(x, y) { - log.info "Executing $x + $y" - // DANGER! This won't throw a compilation issue and fail only at runtime!!! - calcSum3() - log.info("Logging an undefined variable: $z") - } -} \ No newline at end of file diff --git a/java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy b/java-groovy-joint/src/main/groovy/com/baeldung/CalcMath.groovy similarity index 76% rename from java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy rename to java-groovy-joint/src/main/groovy/com/baeldung/CalcMath.groovy index d9709653c7..0e233793b2 100644 --- a/java-groovy-joint/src/main/groovy/com.baeldung/CalcMath.groovy +++ b/java-groovy-joint/src/main/groovy/com/baeldung/CalcMath.groovy @@ -10,6 +10,12 @@ class CalcMath { x + y } + /** + * example of method that in java would throw error at compile time + * @param x + * @param y + * @return + */ def calcSum2(x, y) { log.info "Executing $x + $y" // DANGER! This won't throw a compilation issue and fail only at runtime!!! diff --git a/java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy b/java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy new file mode 100644 index 0000000000..688928468a --- /dev/null +++ b/java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy @@ -0,0 +1,10 @@ +package com.baeldung + +def calcSum(x, y) { + x + y +} + +def calcSum2(x, y) { + // DANGER! This won't throw a compilation issue and fail only at runtime!!! + calcSum3() +} diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/java-groovy-joint/src/main/java/com/baeldung/App.java index 0a201d12e2..7cfeba2024 100644 --- a/java-groovy-joint/src/main/java/com/baeldung/App.java +++ b/java-groovy-joint/src/main/java/com/baeldung/App.java @@ -1,12 +1,20 @@ package com.baeldung; -import groovy.lang.Binding; -import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyShell; +import groovy.lang.*; +import groovy.util.GroovyScriptEngine; +import groovy.util.ResourceException; +import groovy.util.ScriptException; import org.codehaus.groovy.control.CompilerConfiguration; +import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.script.Compilable; +import javax.script.ScriptEngine; +import java.io.File; +import java.io.IOException; +import java.net.URL; + /** * Hello world! * @@ -15,40 +23,84 @@ public class App { private final static Logger LOG = LoggerFactory.getLogger(App.class); private final GroovyClassLoader loader; private final GroovyShell shell; + private final GroovyScriptEngine engine; - private App() { + private App() throws IOException { loader = new GroovyClassLoader(this.getClass().getClassLoader()); CompilerConfiguration config = new CompilerConfiguration(); config.setScriptBaseClass("com.baeldung.CalcScript"); shell = new GroovyShell(loader, new Binding(), config); + engine = new GroovyScriptEngine(new URL[] { new File("src/main/groovy/com/baeldung/").toURI().toURL() }, this.getClass().getClassLoader()); } - private void runScript(int x, int y) { - Object script = shell.parse(String.format("calcSum(%d,%d)", x, y)); + private void runCompiledClasses(int x, int y) { + Object result1 = new CalcScript().calcSum(x, y); + LOG.info("Result of calcSum() method is {}", result1); + + Object result2 = new CalcMath().calcSum(x, y); + LOG.info("Result of calcSum() method is {}", result2); + } + + private void runShellScript(int x, int y) { + Script script = shell.parse(String.format("calcSum(%d,%d)", x, y)); assert script instanceof CalcScript; - Object result = ((CalcScript) script).run(); + Object result = script.run(); LOG.info("Result of run() method is {}", result); Object script2 = shell.parse("CalcScript"); + assert script2 instanceof CalcScript; Object result2 = ((CalcScript) script2).calcSum(x + 7, y + 7); LOG.info("Result of calcSum() method is {}", result2); + Script script3 = shell.parse(""); + assert script3 instanceof CalcScript; + Object result3 = script3.invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); + LOG.info("Result of run() method is {}", result3); + } - private void runClass(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + private void runClassWithLoader(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException { Class calcClass = loader.loadClass("com.baeldung.CalcMath"); Object calc = calcClass.newInstance(); assert calc instanceof CalcMath; Object result = ((CalcMath) calc).calcSum(x, y); LOG.info("Result is {}", result); + + Object result2 = ((GroovyObject) calc).invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); + LOG.info("Result is {}", result2); + } - public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException { + private void runClassWithEngine(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException, ResourceException, ScriptException { + + Class calcClass = engine.loadScriptByName("CalcMath.groovy"); + GroovyObject calc = calcClass.newInstance(); + Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); + //WARNING the following will throw a ClassCastException + //((CalcMath)calc).calcSum(1,2); + LOG.info("Result is {}", result); + } + + private void runClassWithEngineFactory(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException, ResourceException, ScriptException, javax.script.ScriptException { + ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine(); + Class calcClass = (Class) ((Compilable) engine).compile("com.baeldung.CalcMath").eval(); + Object calc = calcClass.newInstance(); + Object result = ((CalcMath) calc).calcSum(1, 20); + LOG.info("Result is {}", result); + } + + public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, ResourceException, ScriptException, IOException, javax.script.ScriptException { App app = new App(); + LOG.info("Running an already compiled groovy class instance..."); + app.runCompiledClasses(5, 10); LOG.info("Running a groovy script..."); - app.runScript(5, 10); + app.runShellScript(5, 10); LOG.info("Running a groovy class..."); - app.runClass(1, 3); + app.runClassWithLoader(1, 3); + LOG.info("Running a groovy class using the engine..."); + app.runClassWithEngine(10, 30); + LOG.info("Running a groovy class using the engine factory..."); + app.runClassWithEngineFactory(10, 30); } } From b9999c1af1ae2cce154d765ad74d5153cf274e07 Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Mon, 27 May 2019 11:25:19 +0100 Subject: [PATCH 3/8] BAEL-2899: separating static and dynamic classes examples --- .../src/main/java/com/baeldung/App.java | 97 +++++++++---------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/java-groovy-joint/src/main/java/com/baeldung/App.java index 7cfeba2024..7e24ec2c16 100644 --- a/java-groovy-joint/src/main/java/com/baeldung/App.java +++ b/java-groovy-joint/src/main/java/com/baeldung/App.java @@ -4,14 +4,14 @@ import groovy.lang.*; import groovy.util.GroovyScriptEngine; import groovy.util.ResourceException; import groovy.util.ScriptException; -import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.script.Compilable; import javax.script.ScriptEngine; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.net.URL; @@ -24,83 +24,76 @@ public class App { private final GroovyClassLoader loader; private final GroovyShell shell; private final GroovyScriptEngine engine; + private final ScriptEngine engineFromFactory; private App() throws IOException { loader = new GroovyClassLoader(this.getClass().getClassLoader()); - CompilerConfiguration config = new CompilerConfiguration(); - config.setScriptBaseClass("com.baeldung.CalcScript"); - shell = new GroovyShell(loader, new Binding(), config); + shell = new GroovyShell(loader, new Binding()); engine = new GroovyScriptEngine(new URL[] { new File("src/main/groovy/com/baeldung/").toURI().toURL() }, this.getClass().getClassLoader()); + engineFromFactory = new GroovyScriptEngineFactory().getScriptEngine(); + } private void runCompiledClasses(int x, int y) { + LOG.info("Executing {} + {}", x, y); Object result1 = new CalcScript().calcSum(x, y); - LOG.info("Result of calcSum() method is {}", result1); + LOG.info("Result of CalcScript.calcSum() method is {}", result1); Object result2 = new CalcMath().calcSum(x, y); - LOG.info("Result of calcSum() method is {}", result2); + LOG.info("Result of CalcMath.calcSum() method is {}", result2); } - private void runShellScript(int x, int y) { - Script script = shell.parse(String.format("calcSum(%d,%d)", x, y)); - assert script instanceof CalcScript; - Object result = script.run(); - LOG.info("Result of run() method is {}", result); - - Object script2 = shell.parse("CalcScript"); - assert script2 instanceof CalcScript; - Object result2 = ((CalcScript) script2).calcSum(x + 7, y + 7); - LOG.info("Result of calcSum() method is {}", result2); - - Script script3 = shell.parse(""); - assert script3 instanceof CalcScript; - Object result3 = script3.invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); - LOG.info("Result of run() method is {}", result3); - + private void runDynamicShellScript(int x, int y) throws IOException { + Script script = shell.parse(new File("src/main/groovy/com/baeldung/", "CalcScript.groovy")); + LOG.info("Executing {} + {}", x, y); + Object result = script.invokeMethod("calcSum", new Object[] { x, y }); + LOG.info("Result of CalcScript.calcSum() method is {}", result); } - private void runClassWithLoader(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException { - Class calcClass = loader.loadClass("com.baeldung.CalcMath"); + private void runDynamicClassWithLoader(int x, int y) throws IllegalAccessException, InstantiationException, IOException { + Class calcClass = loader.parseClass(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy")); Object calc = calcClass.newInstance(); - assert calc instanceof CalcMath; - - Object result = ((CalcMath) calc).calcSum(x, y); - LOG.info("Result is {}", result); - - Object result2 = ((GroovyObject) calc).invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); - LOG.info("Result is {}", result2); - + Object result = ((GroovyObject) calc).invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); + LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runClassWithEngine(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException, ResourceException, ScriptException { + private void runDynamicClassWithEngine(int x, int y) throws IllegalAccessException, InstantiationException, ResourceException, ScriptException { Class calcClass = engine.loadScriptByName("CalcMath.groovy"); GroovyObject calc = calcClass.newInstance(); - Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); //WARNING the following will throw a ClassCastException //((CalcMath)calc).calcSum(1,2); - LOG.info("Result is {}", result); + Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); + LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runClassWithEngineFactory(int x, int y) throws ClassNotFoundException, IllegalAccessException, InstantiationException, ResourceException, ScriptException, javax.script.ScriptException { - ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine(); - Class calcClass = (Class) ((Compilable) engine).compile("com.baeldung.CalcMath").eval(); - Object calc = calcClass.newInstance(); - Object result = ((CalcMath) calc).calcSum(1, 20); - LOG.info("Result is {}", result); + private void runDynamicClassWithEngineFactory(int x, int y) throws IllegalAccessException, InstantiationException, javax.script.ScriptException, FileNotFoundException { + Class calcClas = (Class) engineFromFactory.eval(new FileReader(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy"))); + GroovyObject calc = (GroovyObject) calcClas.newInstance(); + Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); + LOG.info("Result of CalcMath.calcSum() method is {}", result); + } + + private void runStaticCompiledClasses() { + LOG.info("Running the Groovy classes compiled statically..."); + runCompiledClasses(5, 10); + + } + + private void runDynamicCompiledClasses() throws IOException, IllegalAccessException, InstantiationException, ClassNotFoundException, ResourceException, ScriptException, javax.script.ScriptException { + LOG.info("Running a dynamic groovy script..."); + runDynamicShellScript(5, 10); + LOG.info("Running a dynamic groovy class with GroovyClassLoader..."); + runDynamicClassWithLoader(10, 30); + LOG.info("Running a dynamic groovy class with GroovyScriptEngine..."); + runDynamicClassWithEngine(15, 0); + LOG.info("Running a dynamic groovy class with GroovyScriptEngine JSR223..."); + runDynamicClassWithEngineFactory(5, 6); } public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, ResourceException, ScriptException, IOException, javax.script.ScriptException { App app = new App(); - LOG.info("Running an already compiled groovy class instance..."); - app.runCompiledClasses(5, 10); - LOG.info("Running a groovy script..."); - app.runShellScript(5, 10); - LOG.info("Running a groovy class..."); - app.runClassWithLoader(1, 3); - LOG.info("Running a groovy class using the engine..."); - app.runClassWithEngine(10, 30); - LOG.info("Running a groovy class using the engine factory..."); - app.runClassWithEngineFactory(10, 30); + app.runStaticCompiledClasses(); + app.runDynamicCompiledClasses(); } } From 224ceb98d5f99f3c445647d65c7d2d864838e6c8 Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Mon, 27 May 2019 12:33:09 +0100 Subject: [PATCH 4/8] BAEL-2899: formatting --- .../src/main/java/com/baeldung/App.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/java-groovy-joint/src/main/java/com/baeldung/App.java index 7e24ec2c16..c964d1c7cd 100644 --- a/java-groovy-joint/src/main/java/com/baeldung/App.java +++ b/java-groovy-joint/src/main/java/com/baeldung/App.java @@ -29,9 +29,10 @@ public class App { private App() throws IOException { loader = new GroovyClassLoader(this.getClass().getClassLoader()); shell = new GroovyShell(loader, new Binding()); - engine = new GroovyScriptEngine(new URL[] { new File("src/main/groovy/com/baeldung/").toURI().toURL() }, this.getClass().getClassLoader()); + engine = new GroovyScriptEngine(new URL[] { + new File("src/main/groovy/com/baeldung/").toURI().toURL() + }, this.getClass().getClassLoader()); engineFromFactory = new GroovyScriptEngineFactory().getScriptEngine(); - } private void runCompiledClasses(int x, int y) { @@ -51,9 +52,10 @@ public class App { } private void runDynamicClassWithLoader(int x, int y) throws IllegalAccessException, InstantiationException, IOException { - Class calcClass = loader.parseClass(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy")); - Object calc = calcClass.newInstance(); - Object result = ((GroovyObject) calc).invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); + Class calcClass = loader.parseClass( + new File("src/main/groovy/com/baeldung/", "CalcMath.groovy")); + GroovyObject calc = (GroovyObject) calcClass.newInstance(); + Object result = calc.invokeMethod("calcSum", new Object[] { x + 14, y + 14 }); LOG.info("Result of CalcMath.calcSum() method is {}", result); } @@ -68,7 +70,8 @@ public class App { } private void runDynamicClassWithEngineFactory(int x, int y) throws IllegalAccessException, InstantiationException, javax.script.ScriptException, FileNotFoundException { - Class calcClas = (Class) engineFromFactory.eval(new FileReader(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy"))); + Class calcClas = (Class) engineFromFactory.eval( + new FileReader(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy"))); GroovyObject calc = (GroovyObject) calcClas.newInstance(); Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); LOG.info("Result of CalcMath.calcSum() method is {}", result); From 8c8678159d958bd044ab3544109cf328876be79e Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Mon, 27 May 2019 12:47:30 +0100 Subject: [PATCH 5/8] BAEL-2899: reducing line length --- .../src/main/java/com/baeldung/App.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/java-groovy-joint/src/main/java/com/baeldung/App.java index c964d1c7cd..6c92c3a0b1 100644 --- a/java-groovy-joint/src/main/java/com/baeldung/App.java +++ b/java-groovy-joint/src/main/java/com/baeldung/App.java @@ -59,7 +59,8 @@ public class App { LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runDynamicClassWithEngine(int x, int y) throws IllegalAccessException, InstantiationException, ResourceException, ScriptException { + private void runDynamicClassWithEngine(int x, int y) throws IllegalAccessException, + InstantiationException, ResourceException, ScriptException { Class calcClass = engine.loadScriptByName("CalcMath.groovy"); GroovyObject calc = calcClass.newInstance(); @@ -69,7 +70,8 @@ public class App { LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runDynamicClassWithEngineFactory(int x, int y) throws IllegalAccessException, InstantiationException, javax.script.ScriptException, FileNotFoundException { + private void runDynamicClassWithEngineFactory(int x, int y) throws IllegalAccessException, + InstantiationException, javax.script.ScriptException, FileNotFoundException { Class calcClas = (Class) engineFromFactory.eval( new FileReader(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy"))); GroovyObject calc = (GroovyObject) calcClas.newInstance(); @@ -83,7 +85,8 @@ public class App { } - private void runDynamicCompiledClasses() throws IOException, IllegalAccessException, InstantiationException, ClassNotFoundException, ResourceException, ScriptException, javax.script.ScriptException { + private void runDynamicCompiledClasses() throws IOException, IllegalAccessException, InstantiationException, + ResourceException, ScriptException, javax.script.ScriptException { LOG.info("Running a dynamic groovy script..."); runDynamicShellScript(5, 10); LOG.info("Running a dynamic groovy class with GroovyClassLoader..."); @@ -94,7 +97,8 @@ public class App { runDynamicClassWithEngineFactory(5, 6); } - public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, ResourceException, ScriptException, IOException, javax.script.ScriptException { + public static void main(String[] args) throws InstantiationException, IllegalAccessException, + ResourceException, ScriptException, IOException, javax.script.ScriptException { App app = new App(); app.runStaticCompiledClasses(); app.runDynamicCompiledClasses(); From f689fa9e5e366ab2aaaafdd137851fb0b269e090 Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Thu, 30 May 2019 18:03:11 +0100 Subject: [PATCH 6/8] BAEL-2899: moving joint compilation to core-groovy-2 module --- .../gmavenplus-pom.xml | 132 +++++++++-------- core-groovy-2/pom.xml | 84 ++++++----- .../main/groovy/com/baeldung/CalcMath.groovy | 0 .../groovy/com/baeldung/CalcScript.groovy | 0 .../src/main/java/com/baeldung/App.java | 0 java-groovy-joint/pom.xml | 133 ------------------ 6 files changed, 126 insertions(+), 223 deletions(-) rename {java-groovy-joint => core-groovy-2}/gmavenplus-pom.xml (57%) rename {java-groovy-joint => core-groovy-2}/src/main/groovy/com/baeldung/CalcMath.groovy (100%) rename {java-groovy-joint => core-groovy-2}/src/main/groovy/com/baeldung/CalcScript.groovy (100%) rename {java-groovy-joint => core-groovy-2}/src/main/java/com/baeldung/App.java (100%) delete mode 100644 java-groovy-joint/pom.xml diff --git a/java-groovy-joint/gmavenplus-pom.xml b/core-groovy-2/gmavenplus-pom.xml similarity index 57% rename from java-groovy-joint/gmavenplus-pom.xml rename to core-groovy-2/gmavenplus-pom.xml index b34eeb292d..924dab94d1 100644 --- a/java-groovy-joint/gmavenplus-pom.xml +++ b/core-groovy-2/gmavenplus-pom.xml @@ -1,50 +1,19 @@ - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - java-groovy-joint - 0.1.0-SNAPSHOT - java-groovy-joint + core-groovy-2 + 1.0-SNAPSHOT + core-groovy-2 + jar + com.baeldung parent-modules 1.0.0-SNAPSHOT - - UTF-8 - 3.9 - 1.8 - 3.8.1 - 1.2.3 - 2.5.7 - - - - - bintray - Groovy Bintray - https://dl.bintray.com/groovy/maven - - never - - - false - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - ch.qos.logback - logback-classic - ${logback.version} - org.codehaus.groovy groovy-all @@ -52,30 +21,29 @@ pom - junit - junit - 4.11 + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} test - + src/main/groovy + src/main/java - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - - com.baeldung.App - true - - - - org.codehaus.gmavenplus gmavenplus-plugin @@ -100,7 +68,7 @@ org.codehaus.groovy groovy-all - 2.5.6 + ${groovy.version} runtime pom @@ -110,8 +78,42 @@ org.apache.maven.plugins maven-compiler-plugin - - + + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + + + + maven-surefire-plugin + 2.20.1 + + false + + **/*Test.java + **/*Spec.java + + + org.apache.maven.plugins @@ -144,5 +146,19 @@ + + + central + http://jcenter.bintray.com + + + + 1.0.0 + 2.5.7 + 2.4.0 + 1.1-groovy-2.4 + 1.6 + + diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml index 77de9c8fc8..0ade31acdb 100644 --- a/core-groovy-2/pom.xml +++ b/core-groovy-2/pom.xml @@ -14,26 +14,11 @@ - - org.codehaus.groovy - groovy - ${groovy.version} - org.codehaus.groovy groovy-all - ${groovy-all.version} - pom - - - org.codehaus.groovy - groovy-dateutil ${groovy.version} - - - org.codehaus.groovy - groovy-sql - ${groovy-sql.version} + pom org.junit.platform @@ -56,21 +41,29 @@ + src/main/groovy + src/main/java - org.codehaus.gmavenplus - gmavenplus-plugin - ${gmavenplus-plugin.version} - - - - addSources - addTestSources - compile - compileTests - - - + maven-compiler-plugin + 3.8.0 + + groovy-eclipse-compiler + ${java.version} + ${java.version} + + + + org.codehaus.groovy + groovy-eclipse-compiler + 3.3.0-01 + + + org.codehaus.groovy + groovy-eclipse-batch + ${groovy.version}-01 + + maven-failsafe-plugin @@ -108,6 +101,35 @@ + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + + jar-with-dependencies + + + + + com.baeldung.App + + + + + + + make-assembly + + package + + single + + + + @@ -120,9 +142,7 @@ 1.0.0 - 2.5.6 - 2.5.6 - 2.5.6 + 2.5.7 2.4.0 1.1-groovy-2.4 1.6 diff --git a/java-groovy-joint/src/main/groovy/com/baeldung/CalcMath.groovy b/core-groovy-2/src/main/groovy/com/baeldung/CalcMath.groovy similarity index 100% rename from java-groovy-joint/src/main/groovy/com/baeldung/CalcMath.groovy rename to core-groovy-2/src/main/groovy/com/baeldung/CalcMath.groovy diff --git a/java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy b/core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy similarity index 100% rename from java-groovy-joint/src/main/groovy/com/baeldung/CalcScript.groovy rename to core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy diff --git a/java-groovy-joint/src/main/java/com/baeldung/App.java b/core-groovy-2/src/main/java/com/baeldung/App.java similarity index 100% rename from java-groovy-joint/src/main/java/com/baeldung/App.java rename to core-groovy-2/src/main/java/com/baeldung/App.java diff --git a/java-groovy-joint/pom.xml b/java-groovy-joint/pom.xml deleted file mode 100644 index 5ac4768865..0000000000 --- a/java-groovy-joint/pom.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - 4.0.0 - java-groovy-joint - 0.1.0-SNAPSHOT - java-groovy-joint - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - UTF-8 - 3.9 - 1.8 - 3.8.1 - 1.2.3 - 2.5.7 - - - - - bintray - Groovy Bintray - https://dl.bintray.com/groovy/maven - - - never - - - false - - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - org.codehaus.groovy - groovy-all - ${groovy.version} - pom - - - junit - junit - 4.11 - test - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - - com.baeldung.App - true - - - - - - maven-compiler-plugin - 3.8.0 - - groovy-eclipse-compiler - ${java.version} - ${java.version} - - - - org.codehaus.groovy - groovy-eclipse-compiler - 3.3.0-01 - - - org.codehaus.groovy - groovy-eclipse-batch - ${groovy.version}-01 - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.1.0 - - - - jar-with-dependencies - - - - - com.baeldung.App - - - - - - - make-assembly - - package - - single - - - - - - - - - From 9e0e8a6b0b51de297b344cc59364cb8251571b65 Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Sun, 2 Jun 2019 11:09:12 +0100 Subject: [PATCH 7/8] [BAEL-2899] removed exception and added dependencies needed for correct compilation --- core-groovy-2/gmavenplus-pom.xml | 18 ++++++- core-groovy-2/pom.xml | 54 +++++++++++++++---- .../{App.java => MyJointCompilationApp.java} | 25 +++++---- 3 files changed, 76 insertions(+), 21 deletions(-) rename core-groovy-2/src/main/java/com/baeldung/{App.java => MyJointCompilationApp.java} (85%) diff --git a/core-groovy-2/gmavenplus-pom.xml b/core-groovy-2/gmavenplus-pom.xml index 924dab94d1..54c89b9834 100644 --- a/core-groovy-2/gmavenplus-pom.xml +++ b/core-groovy-2/gmavenplus-pom.xml @@ -14,6 +14,16 @@ + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + ch.qos.logback + logback-classic + ${logback.version} + org.codehaus.groovy groovy-all @@ -127,7 +137,7 @@ - com.baeldung.App + com.baeldung.MyJointCompilationApp @@ -154,10 +164,14 @@ + UTF-8 1.0.0 - 2.5.7 2.4.0 1.1-groovy-2.4 + 3.9 + 1.8 + 1.2.3 + 2.5.7 1.6 diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml index 0ade31acdb..b945546c8a 100644 --- a/core-groovy-2/pom.xml +++ b/core-groovy-2/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-groovy-2 1.0-SNAPSHOT @@ -14,6 +14,16 @@ + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + ch.qos.logback + logback-classic + ${logback.version} + org.codehaus.groovy groovy-all @@ -44,6 +54,12 @@ src/main/groovy src/main/java + + org.codehaus.groovy + groovy-eclipse-compiler + 3.3.0-01 + true + maven-compiler-plugin 3.8.0 @@ -94,11 +110,11 @@ maven-surefire-plugin 2.20.1 - false - - **/*Test.java - **/*Spec.java - + false + + **/*Test.java + **/*Spec.java + @@ -114,7 +130,7 @@ - com.baeldung.App + com.baeldung.MyJointCompilationApp @@ -140,12 +156,32 @@ + + + bintray + Groovy Bintray + https://dl.bintray.com/groovy/maven + + + never + + + false + + + + + 1.0.0 - 2.5.7 2.4.0 1.1-groovy-2.4 - 1.6 + 3.9 + 1.8 + 3.8.1 + 1.2.3 + 2.5.7 + UTF-8 diff --git a/core-groovy-2/src/main/java/com/baeldung/App.java b/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java similarity index 85% rename from core-groovy-2/src/main/java/com/baeldung/App.java rename to core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java index 6c92c3a0b1..2be2e195ef 100644 --- a/core-groovy-2/src/main/java/com/baeldung/App.java +++ b/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java @@ -7,31 +7,36 @@ import groovy.util.ScriptException; import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import javax.script.ScriptEngine; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; /** * Hello world! * */ -public class App { - private final static Logger LOG = LoggerFactory.getLogger(App.class); +public class MyJointCompilationApp { + private final static Logger LOG = LoggerFactory.getLogger(MyJointCompilationApp.class); private final GroovyClassLoader loader; private final GroovyShell shell; private final GroovyScriptEngine engine; private final ScriptEngine engineFromFactory; - private App() throws IOException { + public MyJointCompilationApp() { loader = new GroovyClassLoader(this.getClass().getClassLoader()); shell = new GroovyShell(loader, new Binding()); - engine = new GroovyScriptEngine(new URL[] { - new File("src/main/groovy/com/baeldung/").toURI().toURL() - }, this.getClass().getClassLoader()); + + URL url = null; + try { + url = new File("src/main/groovy/com/baeldung/").toURI().toURL(); + } catch (MalformedURLException e) { + LOG.error("Exception while creating url", e); + } + engine = new GroovyScriptEngine(new URL[] {url}, this.getClass().getClassLoader()); engineFromFactory = new GroovyScriptEngineFactory().getScriptEngine(); } @@ -99,8 +104,8 @@ public class App { public static void main(String[] args) throws InstantiationException, IllegalAccessException, ResourceException, ScriptException, IOException, javax.script.ScriptException { - App app = new App(); - app.runStaticCompiledClasses(); - app.runDynamicCompiledClasses(); + MyJointCompilationApp myJointCompilationApp = new MyJointCompilationApp(); + myJointCompilationApp.runStaticCompiledClasses(); + myJointCompilationApp.runDynamicCompiledClasses(); } } From dd69f71a9cb22f1c36689415ef9a10ecf59d3ddd Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Sun, 9 Jun 2019 21:18:13 +0100 Subject: [PATCH 8/8] [BAEL-2899] adding more information and changing methods names --- .../groovy/com/baeldung/CalcScript.groovy | 8 ++- .../com/baeldung/MyJointCompilationApp.java | 51 +++++++++++-------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy b/core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy index 688928468a..84615b2217 100644 --- a/core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy +++ b/core-groovy-2/src/main/groovy/com/baeldung/CalcScript.groovy @@ -5,6 +5,12 @@ def calcSum(x, y) { } def calcSum2(x, y) { - // DANGER! This won't throw a compilation issue and fail only at runtime!!! + // DANGER! The variable "log" may be undefined + log.info "Executing $x + $y" + // DANGER! This method doesn't exist! calcSum3() + // DANGER! The logged variable "z" is undefined! + log.info("Logging an undefined variable: $z") } + +calcSum(1,5) diff --git a/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java b/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java index 2be2e195ef..c49f6edc30 100644 --- a/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java +++ b/core-groovy-2/src/main/java/com/baeldung/MyJointCompilationApp.java @@ -40,7 +40,7 @@ public class MyJointCompilationApp { engineFromFactory = new GroovyScriptEngineFactory().getScriptEngine(); } - private void runCompiledClasses(int x, int y) { + private void addWithCompiledClasses(int x, int y) { LOG.info("Executing {} + {}", x, y); Object result1 = new CalcScript().calcSum(x, y); LOG.info("Result of CalcScript.calcSum() method is {}", result1); @@ -49,14 +49,21 @@ public class MyJointCompilationApp { LOG.info("Result of CalcMath.calcSum() method is {}", result2); } - private void runDynamicShellScript(int x, int y) throws IOException { + private void addWithGroovyShell(int x, int y) throws IOException { Script script = shell.parse(new File("src/main/groovy/com/baeldung/", "CalcScript.groovy")); LOG.info("Executing {} + {}", x, y); Object result = script.invokeMethod("calcSum", new Object[] { x, y }); LOG.info("Result of CalcScript.calcSum() method is {}", result); } - private void runDynamicClassWithLoader(int x, int y) throws IllegalAccessException, InstantiationException, IOException { + private void addWithGroovyShellRun() throws IOException { + Script script = shell.parse(new File("src/main/groovy/com/baeldung/", "CalcScript.groovy")); + LOG.info("Executing script run method"); + Object result = script.run(); + LOG.info("Result of CalcScript.run() method is {}", result); + } + + private void addWithGroovyClassLoader(int x, int y) throws IllegalAccessException, InstantiationException, IOException { Class calcClass = loader.parseClass( new File("src/main/groovy/com/baeldung/", "CalcMath.groovy")); GroovyObject calc = (GroovyObject) calcClass.newInstance(); @@ -64,9 +71,8 @@ public class MyJointCompilationApp { LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runDynamicClassWithEngine(int x, int y) throws IllegalAccessException, + private void addWithGroovyScriptEngine(int x, int y) throws IllegalAccessException, InstantiationException, ResourceException, ScriptException { - Class calcClass = engine.loadScriptByName("CalcMath.groovy"); GroovyObject calc = calcClass.newInstance(); //WARNING the following will throw a ClassCastException @@ -75,37 +81,40 @@ public class MyJointCompilationApp { LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runDynamicClassWithEngineFactory(int x, int y) throws IllegalAccessException, + private void addWithEngineFactory(int x, int y) throws IllegalAccessException, InstantiationException, javax.script.ScriptException, FileNotFoundException { - Class calcClas = (Class) engineFromFactory.eval( + Class calcClass = (Class) engineFromFactory.eval( new FileReader(new File("src/main/groovy/com/baeldung/", "CalcMath.groovy"))); - GroovyObject calc = (GroovyObject) calcClas.newInstance(); + GroovyObject calc = (GroovyObject) calcClass.newInstance(); Object result = calc.invokeMethod("calcSum", new Object[] { x, y }); LOG.info("Result of CalcMath.calcSum() method is {}", result); } - private void runStaticCompiledClasses() { + private void addWithStaticCompiledClasses() { LOG.info("Running the Groovy classes compiled statically..."); - runCompiledClasses(5, 10); + addWithCompiledClasses(5, 10); } - private void runDynamicCompiledClasses() throws IOException, IllegalAccessException, InstantiationException, + private void addWithDynamicCompiledClasses() throws IOException, IllegalAccessException, InstantiationException, ResourceException, ScriptException, javax.script.ScriptException { - LOG.info("Running a dynamic groovy script..."); - runDynamicShellScript(5, 10); - LOG.info("Running a dynamic groovy class with GroovyClassLoader..."); - runDynamicClassWithLoader(10, 30); - LOG.info("Running a dynamic groovy class with GroovyScriptEngine..."); - runDynamicClassWithEngine(15, 0); - LOG.info("Running a dynamic groovy class with GroovyScriptEngine JSR223..."); - runDynamicClassWithEngineFactory(5, 6); + LOG.info("Invocation of a dynamic groovy script..."); + addWithGroovyShell(5, 10); + LOG.info("Invocation of the run method of a dynamic groovy script..."); + addWithGroovyShellRun(); + LOG.info("Invocation of a dynamic groovy class loaded with GroovyClassLoader..."); + addWithGroovyClassLoader(10, 30); + LOG.info("Invocation of a dynamic groovy class loaded with GroovyScriptEngine..."); + addWithGroovyScriptEngine(15, 0); + LOG.info("Invocation of a dynamic groovy class loaded with GroovyScriptEngine JSR223..."); + addWithEngineFactory(5, 6); } public static void main(String[] args) throws InstantiationException, IllegalAccessException, ResourceException, ScriptException, IOException, javax.script.ScriptException { MyJointCompilationApp myJointCompilationApp = new MyJointCompilationApp(); - myJointCompilationApp.runStaticCompiledClasses(); - myJointCompilationApp.runDynamicCompiledClasses(); + LOG.info("Example of addition operation via Groovy scripts integration with Java."); + myJointCompilationApp.addWithStaticCompiledClasses(); + myJointCompilationApp.addWithDynamicCompiledClasses(); } }