在非Eclipse环境中使用Eclipse JDT SDK生成AST时发生异常 [英] Exception while generating AST using Eclipse JDT SDK in a non-eclipse environment

查看:479
本文介绍了在非Eclipse环境中使用Eclipse JDT SDK生成AST时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在非蚀环境中使用jdt的AST生成功能(作为另一个基本Java ide的插件)。当我在eclipse中运行它时,我的程序可以正确创建AST,但是当我从ide测试插件时,我会遇到以下异常:

I'm trying to use the jdt's AST generation feature in a non-eclipse environment(as a plugin for another basic java ide). My program creates the AST correctly when I run it inside eclipse, but when I test the plugin it from the ide I get this exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: ignoreMethodBodies 
at org.eclipse.jdt.core.dom.CompilationUnitResolver.parse(CompilationUnitResolver.java:491)
at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1200) 
at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java :807) 
at mytreetest.TreeMaker.buildTree(Unknown Source)
...
(further stack trace)
...

我使用的代码非常基本:

The code I've used is quite basic:

代码:

ASTParser parser = ASTParser.newParser(AST.JLS4);
String src = readFile(filePath);
parser.setSource(src.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Map<String, String> options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);

我浏览了org.eclipse.jdt.core.dom.CompilationUnitResolver和org的源代码。 eclipse.jdt.internal.compiler.impl.CompilerOptions。

I went through the source code of org.eclipse.jdt.core.dom.CompilationUnitResolver and org.eclipse.jdt.internal.compiler.impl.CompilerOptions. CompilerOptions does have a public boolean field called ignoreMethodBodies.

什么可能导致此错误?

请帮助我

这是我包含的Eclipse jar文件:

Here are the eclipse jar files I've included :

org.eclipse.core.contenttype_3.4.100.v20110423-0524.jar
org.eclipse.core.jobs_3.5.100.v20110404.jar
org.eclipse.core.resources_3.7100.v20110510-0712.jar
org.eclipse.core.runtime_3.7.O.v20110110.jar
org.eclipse.equinoxcommon_3.6.O.v20110523.jar
org.eclipse.equinox.preferences_3.4.1.R37x_v20110725.jar
org.eclipse.jdt.compiler.apt_1.O.400.v0110816-0800.jar
org.eclipse.jdt.compiler.tooLl.O.100.v_B76_R37x.jar
org.edipse.jdt.core_3.7.1.v_B76_R37x.jar
org.eclipse.jface3.7.0J20110522-1430.jar
org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar
org.eclipse.osgi.utiL3.2.200.v20110110.jar
org.eclipse.text3.5101 .r371y20110810-O800jar

更新:

我已经找到了解决方法。我运行此代码的Java端使用的是ecj。问题在于ecj.jar与我随附于插件中的jdt-core模块冲突。用jdt-core(org.eclipse.jdt.core_XX.XX.jar和其余的jar)替换ide的ecj并更新其类路径即可解决此问题。

I've found the fix for this. The java-ide from which I was running this code was using ecj. The problem was that ecj.jar was clashing with the jdt-core modules I'd included with my plugin. Replacing the ide's ecj with jdt-core(org.eclipse.jdt.core_XX.XX.jar and the rest of the jars) and updating its classpath solved the problem.

推荐答案

我使用JDT是一个动态Web项目,并且遇到了相同的错误。

I used JDT is a Dynamic web project, and got the same error.

感谢Manindra Moharana的回答,我发现了错误的原因。

Thanks to Manindra Moharana's answer, I fount out the cause of the error.

首先,我在类路径中添加了 Apache Tomcat 6.0服务器库。
不幸的是,Tomcat也使用ecj,它与jdt.core中的CompilerOptions类冲突。

At first, I added "Apache Tomcat 6.0" server library to the classpath. Unfortunately, Tomcat as well use ecj, which conflict with the CompilerOptions class in jdt.core.

因此解决方案是从类路径中删除Tomcat服务器库。

So the solution is remove the Tomcat server library from the classpath.

现在一切似乎都很好。

这篇关于在非Eclipse环境中使用Eclipse JDT SDK生成AST时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆