Java에서 .groovy 파일을 실행하려고하지만 Java와 Groovy에서 처음 사용하는 경우 몇 가지 문제가 있습니다. 나는 더 많은 것을 배우기 위해이 일을하고 있으며 누군가 내가 잘못하고있는 것을 말해 줄 수 있다면 감사 할 것입니다.Java에서 groovy 파일 실행
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyShell;
import javax.naming.Binding;
import java.io.File;
public class testClass extends GroovyShell{
public static void main(String[] args){
try{
ClassLoader parent = testClass.class.getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(new File("src/testg.groovy"));
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
Object[] args1 = {};
groovyObject.invokeMethod("run",args1);
}catch(Exception e) {
System.out.println("error loading file");
}
}
}
나는 다음과 같은 오류가 점점 오전 :
Groovyc: Cannot compile Groovy files: no Groovy library is defined for module 'Prep'
Using javac 1.7.0_09 to compile java sources
Compilation completed with 1 error and 0 warnings in 9 sec
1 error
0 warnings
Groovyc: Internal groovyc error: code 1
아니면 누군가가 나에게 예를 들어, 실행하는 방법의 예를 줄 수 hello world 스크립트는 자바로 그루비로 작성되었습니다.
어떻게 컴파일하나요? 'envHealth' 란 무엇입니까? (어디서나 참조 할 수는 없습니다) –
안녕하세요, intellij ide에서 컴파일 중입니다. 미안 나는 놀고 있었고, envHeath는 클래스 이름 (testClass)으로되어 있었고 내 게시물에서도 수정했다. – user648244