From 9e0e8a6b0b51de297b344cc59364cb8251571b65 Mon Sep 17 00:00:00 2001 From: Gian Mario Contessa Date: Sun, 2 Jun 2019 11:09:12 +0100 Subject: [PATCH] [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(); } }