微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决我在 Eclipse 中使用 ASTParser 时遇到问题

我正在尝试在 Eclipse 中使用 ASTParser,但遇到了 NoClassDefFoundError。 我已经遵循了一些指南并导入了相关的 9 罐。 详情如下:

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));
    
    
}

}

included jars

the error report

command line

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

解决方法

项目>属性:Java构建路径中,标签移动中的所有JAR 模块路径类路径

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。