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

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

问题描述

嘿,所有。我正在学校的一个项目,我们给予的.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文件夹中,并得到相同的错误。 Google搜索和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接口。 Doh。感谢您的帮助,但我确实学到了很多关于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构建路径 - >库 - >添加类文件夹。请记住,你必须在包中指定包含类文件的根文件夹。

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下的类目录中(但不在项目A的构建路径中),那么应该将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文件? (Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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