如何在项目中导入 eclipse JDT 类
我想在课堂上进行以下导入。
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
如何在 Eclipse 中导入 JDT? 干杯。
I want to do the following imports in a class.
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
How can I import the JDT within Eclipse?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非我误解了您的意思,否则您只需要在类路径中包含 JDT JAR 文件即可; 它们都可以在您的 Eclipse 插件目录中找到。 因此,对于您的项目,在 Package Explorer 中右键单击项目名称,转到“构建路径...”子菜单,然后选择“配置构建路径”。 然后在 Libraries 选项卡中,使用“Add external JARs”按钮从 Eclipse 插件目录添加每个相关的 JAR 文件。
Unless I'm misunderstanding you, you just need to include the JDT JAR files on your classpath; they're all available in your Eclipse plugins directory. So for your project, right-click on the project's name in the Package Explorer, go to the Build Path... submenu, and choose Configure Build Path. Then in the Libraries tab, use the "Add External JARs" button to add each of the relevant JAR files from the Eclipse plugins directory.
如果您正在为 Eclipse 编写插件,那么您实际上不应该尝试实例化
内部
包。 根据此 API 参与规则对于其他包,请将包名称添加到清单中的
Import-Package
条目中。JDT 有一些扩展点,但如果您想要做的事情超出了这些扩展点,那么恐怕您就不走运了。
如果您只是想在代码中使用编译器,而不依赖于 JDK(即 JRE),那么我会考虑使用更独立的基于 Java 的 Java 编译器,例如 Janino。
If your'e writing plugins for Eclipse, you shouldn't really be trying to instantiate the
internal
packages. According to this API Rules of EngagementFor the others, add the package name to the
Import-Package
entry in your manifest.There are extension points into the JDT, but if what you want to do falls outside of these, then I'm afraid you're out of luck.
If you're just looking to use a compiler in your code, without relying on the JDK (i.e. on a JRE), then I would consider shipping with a more standalone Java based Java compiler like Janino.
如果您需要这些类,那么您可能已经在插件项目中了。 您应该能够通过在 Eclipse 抱怨导入的行上应用快速修复“修复项目设置...”(Ctrl+1) 来导入这些类。 这会将所需的插件添加到 META-INF 目录中的 MANIFEST.MF 文件中(在您的情况下为 org.eclipse.jdt.core 和 org.eclipse.jface.text)。 您还可以在 MANIFEST.MF 文件中手动添加它们。 如果您的项目是无插件项目(并且您没有 MANIFEST.MF 文件),您可以通过右键单击项目 -> 进行转换。 偏微分方程工具 -> 首先将项目转换为插件项目。 如果您以正常方式(“配置构建路径”)向插件项目添加依赖项,则类加载在运行时将无法正常工作(尽管它会编译)。
If you need these classes, you are probably in a plug-in project already. You should be able to import these classes by applying the quick fix "Fix project setup..." (Ctrl+1) on the line where Eclipse is complaining about the imports. That will add the required plug-ins to your MANIFEST.MF file in the META-INF directory (org.eclipse.jdt.core and org.eclipse.jface.text in your case). You can also add them manually in your MANIFEST.MF file. If your project is no plug-in project (and you have no MANIFEST.MF file) you can convert it by right-click on the project -> PDE Tools -> Convert Projects to Plug-in Project first. If you add dependencies to plug-in projects in the normal way ("configure build path") the classloading won't work properly at runtime (though it will compile).
我想我找到了一种更简单的方法来做到这一点:
应该可以做到这一点。
I think I found an easier way to do this:
That should do it.