繁体   English   中英

我在 eclipse 中使用 ASTParser 时遇到问题

[英]I'm having an issue with using ASTParser in eclipse

我正在尝试在 eclipse 中使用 ASTParser,但面临 NoClassDefFoundError。 我已经遵循了一些指南并导入了相关的 9 jars。 以下是详细信息:

package test_JDT;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
// import org.eclipse.equinox.common.*;

// import org.eclipse.core.jobs;
class tester {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("hello ast parser");
    String javaFilePath = "C:\\Users\\tabzhang\\eclipse-workspace\\test_JDT\\src\\test_JDT/classdemo.java";
    byte[] input = null;
    try {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(javaFilePath));
        input = new byte[bufferedInputStream.available()];
        bufferedInputStream.read(input);
        bufferedInputStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String str = new String(input);
    System.out.println(str);
    ASTParser astParser = ASTParser.newParser(AST.JLS3);
    astParser.setSource(new String(input).toCharArray());
    astParser.setKind(ASTParser.K_COMPILATION_UNIT);

    CompilationUnit result = (CompilationUnit) (astParser.createAST(null));
    
    
}

}

包括 jars

错误报告

命令行

我应该如何让代码运行良好?

Project > Properties: Java Build Path中,标签Libraries所有JARs 从Modulepath移动到Classpath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM