如何在 Eclipse 的项目中包含 .class 文件?(爪哇) [英] How do I include .class files in my project in Eclipse? (Java)

查看:28
本文介绍了如何在 Eclipse 的项目中包含 .class 文件?(爪哇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我正在为学校开展一个项目,在该项目中我们获得了 .class 文件,但没有包含在我们的代码中的源代码.我正在使用 Eclipse,我想将该文件包含在我的项目中,以便我可以从中实例化对象并使用它.

文件是TokenizerImpl.class,我想这样使用它:

Hey all. I am working on a project for school where we are given the .class file but not the source to include in our code. I am using Eclipse, and I want to include the file in my project so I can instantiate objects from it and use it.

The file is TokenizerImpl.class, and I want to use it like this:

我将文件放在我的项目文件夹中,Eclipse 说无法将 TokenizeImpl 解析为类型",我认为这意味着它找不到类或源.我试着把它放在项目的bin"文件夹中,但得到了同样的错误.谷歌搜索和 SO 搜索似乎没有回答这个问题,所以我会试一试.我该怎么做,哦,聪明的人?

I put the file in my project folder, and Eclipse says that "TokenizeImpl cannot be resolved as a type", which I assume means it cannot find the class or source. I tried putting it in the "bin" folder of the project and got the same error. Google search and SO search didn't seem to answer this, so I will give it a shot. How do I do this, oh wise ones?

哦,亲爱的,我发现问题完全是其他问题.这些解决方案运行良好,但我只是忘记创建 TokenizerImpl 实现的 Tokenizer 接口.多.感谢您的帮助,我确实学到了很多关于 eclipse 的知识.

Oh dear, I found the problem was something else entirely. These solutions worked fine, but I just forgot to create the Tokenizer interface that TokenizerImpl implements. Doh. Thanks for all your help though, I did learn a lot about eclipse.

推荐答案

您可以将包含类文件的目录添加到 Eclipse 项目中,前提是该目录位于您的 Eclipse 项目之一中,无论是在生成的目录中还是在一个你已经创建了.

You can add a directory containing the class files to the Eclipse project, only if it is inside one of your Eclipse projects, either in a generated directory or in one you have created.

这可以通过将类文件夹添加到应用程序的 Java 构建路径来完成.您可以通过访问 Java Build Path -> Libraries -> Add Class Folder 在项目属性中进行设置.请记住,您必须在其包中指定包含类文件的根文件夹.

This can be done by adding the class folder to the Java build path of the application. You can set this in the Project properties, by visiting Java Build Path -> Libraries -> Add Class Folder. Keep in mind, that you will have to specify the root folder containing the class files in their packages.

因此,如果您希望编译器访问 com.stackoverflow.Example.class 存在于项目 A 下的 classes 目录中(但不在项目 A 的构建路径中),那么您应该将 'classes' 添加为类文件夹,而不是 classes/com/stackoverflow 作为类文件夹.

Therefore, if you wish to have the compiler access com.stackoverflow.Example.class present in the classes directory under project A (but not in the build path of project A), then you should add 'classes' as a class folder, and not classes/com/stackoverflow as a class folder.

这篇关于如何在 Eclipse 的项目中包含 .class 文件?(爪哇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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