Java 将 .class 文件添加到 Eclipse 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4328548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding .class files to an Eclipse project
提问by James
This is a total newbie question, but I can't figure it out so I figured that I would ask it here and see what happened.
这是一个完全的新手问题,但我无法弄清楚,所以我想我会在这里问它,看看发生了什么。
Here's the problem: For my java programming class, we are supposed to download a .class file created by our instructors containing a custom-made class with methods that we are supposed to use in an assignment. I already know all of the code to create the class within my actual program, but I can't figure out which directory to place the .class file in. I have tried the src and bin folders inside the project directory, and even placed it directly into the project directory, but nothing seems to work. My instructors say to just put it in the same directory as my java program, but they are using jGRASP. What am I doing wrong?
问题是:对于我的 java 编程课程,我们应该下载由我们的教师创建的 .class 文件,其中包含一个定制的课程,其中包含我们应该在作业中使用的方法。我已经知道在我的实际程序中创建类的所有代码,但我不知道将 .class 文件放在哪个目录中。我已经尝试了项目目录中的 src 和 bin 文件夹,甚至将它放置直接进入项目目录,但似乎没有任何效果。我的导师说只需将它放在与我的 java 程序相同的目录中,但他们使用的是 jGRASP。我究竟做错了什么?
回答by Hovercraft Full Of Eels
You can place the class file anywhere, just be sure to add its directory to your project's build path. Right click on the project, then properties at the bottom then build path, til you find add class folder.
您可以将类文件放在任何地方,只需确保将其目录添加到项目的构建路径中即可。右键单击项目,然后单击底部的属性,然后单击构建路径,直到找到添加类文件夹。
回答by amypellegrini
You have to create a project, or open your project if you have it already, then, while you are in the Java view, select File > New > File. It will open a window, you can create your file there and choose in which project folder do you want to put it. If in that window you press the button "Advanced >>" it will give you the option to "Link to file in the system", check it, and then you can browse your folders to the downloaded file.
您必须创建一个项目,或者打开您的项目(如果您已经拥有该项目),然后在 Java 视图中选择 File > New > File。它将打开一个窗口,您可以在那里创建文件并选择要将其放在哪个项目文件夹中。如果在该窗口中按下“高级 >>”按钮,它将为您提供“链接到系统中的文件”选项,选中它,然后您可以浏览文件夹以找到下载的文件。
I don't know if this solves your problem, it's what I understood from your question.
我不知道这是否解决了您的问题,这是我从您的问题中了解到的。
回答by DwB
Your instructors class file must be in the build-time and the run-time class paths for your project to use it. Instructions assume that you are on a PC.
您的教师类文件必须位于项目的构建时和运行时类路径中才能使用它。说明假定您在 PC 上。
Run-time class path setup
运行时类路径设置
- Create a directory (perhaps C:\JavaRoot\classes). I will refer to this as the Classesdirectory.
- If one does not already exist on your PC, create an environment variable named CLASSPATH
- Add the Classesdirectory to your CLASSPATH envoronment variable
- Download the class in question and put it in the Classesdirectory.
- 创建一个目录(可能是 C:\JavaRoot\classes)。我将把它称为Classes目录。
- 如果您的 PC 上尚不存在,请创建一个名为 CLASSPATH 的环境变量
- 将Classes目录添加到 CLASSPATH 环境变量
- 下载有问题的类并将其放在Classes目录中。
Build-time class path setup
构建时类路径设置
- Right mouse on your project in eclipse.
- Select "Properties".
- Select "Java Build Path".
- Select the "Libraries" tab.
- Click the "Add a Class Folder" button.
- Browse to and select the Classesdirectory you created during "Run-time class path setup" above.
- Click the "OK" button
- 在 Eclipse 中右键单击您的项目。
- 选择“属性”。
- 选择“Java 构建路径”。
- 选择“库”选项卡。
- 点击“添加Ç姑娘文件夹”按钮。
- 浏览并选择您在上面的“运行时类路径设置”期间创建的类目录。
- 单击“确定”按钮
回答by Ibrahim
For Eclipse use the following:
Project > Properties > Java Build Path > Libraries (Tab) > Add External Class Folder (Button)
对于 Eclipse,请使用以下内容:
Project > Properties > Java Build Path > Libraries (Tab) > Add External Class Folder (Button)