-1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <facts>    
    <fact id="ItemPrice" displayName="Item Price">
    <defaultValue>0</defaultValue>
    <script><![CDATA[ 
            Double Value_Sales= 500;
            Double Unit_Sales= 10;
            Double res=Value_Sales/Unit_Sales;
            return res;
    ]]></script>
</fact>
</facts>

Above is the sample groovy script written in xml file for finding item price.

Java code for processing Groovy:

List<Fact> factList = NREUtils.readXml("/SampleDictionary.xml") //cutome API
GroovyShell shell = new GroovyShell();
String scriptStr = factList.get(0).getScript();
Script groovyScript = shell.parse(scriptStr); // return "ItemPrice" script 
Binding binding = new Binding();
groovyScript.setBinding(binding);
Object val = groovyScript.run(); // **Result will be 50**

I would like the corresponding Scala code for the same.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sujith AK
  • 131
  • 1
  • 5
  • 1
    Stack Overflow rewards effort. What have you tried? Post some code that doesn't work so we can see where it's going off track. – jwvh Apr 04 '18 at 08:01
  • List factList = NREUtils.readXml("/SampleDictionary.xml") //cutome API GroovyShell shell = new GroovyShell(); Script groovyScript = shell.parse(factList.get(0).getScript()); // return "ItemPrice" script Binding binding = new Binding(); groovyScript.setBinding(binding); Object val = groovyScript.run(); // Result will be 50 – Sujith AK Apr 04 '18 at 08:46
  • Please edit your question to add additional code and information. Posting code in a comment is, as you can see, rather pointless. (The `edit` link is in the lower left, below your question tags.) – jwvh Apr 04 '18 at 08:51

1 Answers1

0

Without further information on your problem, and being both languages (scala and groovy) executed over the JVM, I would suggest you just to compile your groovy code and include the jar in the classpath of the JVM running your scala code.

Here you have some ideas about how to turn groovy code into usable bytecode: http://docs.groovy-lang.org/latest/html/documentation/tools-groovyc.html

Then do just do as you would with any java library that you would like to call from scala: Using Java libraries in Scala

Jorge_B
  • 9,712
  • 2
  • 17
  • 22