Rahul Gour
Rahul Gour

Reputation: 1

How to resolve the imports of a groovy or java code in spring boot using GroovyClassLoader

I'm try to resolve the imports written in the code that are in the file which is strored in a specific path and make the work properly.

I have the below code for example

import com.itextpdf.layout.Document;

class JSonParser {
  def doc = new Document();
  def static sub(firstNumber, secondNumber) {
    return firstNumber - secondNumber
  }
}

I'm try to resolve the imports that are in the file which is strored in a specific path. I've loaded the code by using GroovyClassLoader as below

Class<?> parseClass = groovyLoader.parseClass(scriptString);

I'm getting the below error

unable to resolve class com.itextpdf.layout.Document

@ line 1, column 1. import com.itextpdf.layout.Document;

I'm getting the above code as String. Can anyone tell me how to get the code compiled successfully along with the imports and make the code work properly by using GroovyClassloader or any other options.

Upvotes: 0

Views: 47

Answers (0)

Related Questions