6

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?

1
  • 1
    Why is he distributing .class files instead of a JAR library or the original source code? Nobody distributes plain .class files in real life - they are always put inside a JAR. Commented Dec 1, 2010 at 20:30

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

but having said that. you must be sure that the class files are in a proper package directory structure. Better to add the external library as a jar file, I suppose.
2

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.

I don't know if this solves your problem, it's what I understood from your question.

Comments

1

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.

Run-time class path setup

  1. Create a directory (perhaps C:\JavaRoot\classes). I will refer to this as the Classes directory.
  2. If one does not already exist on your PC, create an environment variable named CLASSPATH
  3. Add the Classes directory to your CLASSPATH envoronment variable
  4. Download the class in question and put it in the Classes directory.

Build-time class path setup

  1. Right mouse on your project in eclipse.
  2. Select "Properties".
  3. Select "Java Build Path".
  4. Select the "Libraries" tab.
  5. Click the "Add a Class Folder" button.
  6. Browse to and select the Classes directory you created during "Run-time class path setup" above.
  7. Click the "OK" button

Comments

1

For Eclipse use the following:
Project > Properties > Java Build Path > Libraries (Tab) > Add External Class Folder (Button)

Comments

0

If you have a configured project in Eclipse and you manually added a Java class file in some of the project directories, you just need to refresh the project for Eclipse to recognize it:

Right click in your project (in "Project Explorer" view) -> Refresh

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.