简体   繁体   English

将.class文件添加到Eclipse项目中

[英]Adding .class files to an Eclipse project

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. 问题出在这里:对于我的java编程类,我们应该下载由我们的教师创建的.class文件,该文件包含一个定制的类,其中包含我们应该在赋值中使用的方法。 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. 我已经知道在我的实际程序中创建类的所有代码,但我无法确定将.class文件放在哪个目录中。我已经尝试了项目目录中的src和bin文件夹,甚至放置它直接进入项目目录,但似乎没什么用。 My instructors say to just put it in the same directory as my java program, but they are using jGRASP. 我的教师说只是将它放在与我的java程序相同的目录中,但他们使用的是jGRASP。 What am I doing wrong? 我究竟做错了什么?

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. 右键单击项目,然后在底部的属性然后构建路径,直到找到添加类文件夹。

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. 您必须创建项目,或者如果已经拥有项目,则打开项目,然后,当您在Java视图中时,选择“文件”>“新建”>“文件”。 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. 如果在该窗口中按下“高级>>”按钮,它将为您提供“链接到系统中的文件”选项,检查它,然后您可以浏览文件夹到下载的文件。

I don't know if this solves your problem, it's what I understood from your question. 我不知道这是否解决了你的问题,这是我从你的问题中理解的。

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 运行时类路径设置

  1. Create a directory (perhaps C:\\JavaRoot\\classes). 创建一个目录(可能是C:\\ JavaRoot \\ classes)。 I will refer to this as the Classes directory. 我将其称为Classes目录。
  2. If one does not already exist on your PC, create an environment variable named CLASSPATH 如果PC上尚不存在,请创建名为CLASSPATH的环境变量
  3. Add the Classes directory to your CLASSPATH envoronment variable Classes目录添加到CLASSPATH envoronment变量中
  4. Download the class in question and put it in the Classes directory. 下载有问题的类并将其放在Classes目录中。

Build-time class path setup 构建时类路径设置

  1. Right mouse on your project in eclipse. 在Eclipse中右键鼠标项目。
  2. Select "Properties". 选择“属性”。
  3. Select "Java Build Path". 选择“Java Build Path”。
  4. Select the "Libraries" tab. 选择“库”选项卡。
  5. Click the "Add a C lass Folder" button. 单击“添加C lass文件夹”按钮。
  6. Browse to and select the Classes directory you created during "Run-time class path setup" above. 浏览并选择您在上面的“运行时类路径设置”中创建的Classes目录。
  7. Click the "OK" button 单击“确定”按钮

For Eclipse use the following: 对于Eclipse,请使用以下内容:
Project > Properties > Java Build Path > Libraries (Tab) > Add External Class Folder (Button) 项目>属性> Java构建路径>库(选项卡)>添加外部类文件夹(按钮)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM