I'm a new java programmer (and teaching it to high schoolers). The text we
are using supplies us with a Keyboard.class file to use in the
introductory programs. I have the class file on my hard drive. I can't
get my code to work in Eclipse because it is looking for the cs1.Keyboard
class and can't find it.
I've read some info at this site on importing class files, but those
techniques haven't worked for me.
My question, how can I have an Eclipse project find the Keyboard class
when I type in the following at the beginning of the code:
import cs1.Keyboard
You need to copy the .class file into your Eclipse Project; put it in a
directory under your Project named /lib/classes (or any name you choose).
Is the Keyboard class in a package? If so, you must put it in a directory
structure that mirrors the package names. For example, if Keyboard is in a
package named com.foo, then you'll need it in a directory of your project
like this:
MyProject/
lib/
classes/
com/
foo/
Keyboard.class
If Keyboard class has no package (it is in the "default" pacakge) then you
don't need the com/foo/ container, just put it in classes/ directly.
Then open the Properties for your Project, select the Java Build Path
section and then the Libraries tab. There you can click the Add class
folder... button to include the lib/classes directory you added above.
By the way, the tutorials might help you understand Eclipse better. Open
the Eclipse Help Contents and navigate to Java Developer User Guide,
Getting Started and you'll find some tutorials.
Hope this helps,
Eric
**************
Thanks Eric. Follow up questions:
"...put it in a directory under your Project named /lib/classes (or any
name you choose)." Right now the Keyboard.class file is on the c: drive
in folder cs1 I can't put any files under Program Files due to security.
In Eclipse, under my project is a directory "JRE System Library
[jre1.5.0_06]" Underneath there are paths to a directory which ends with
lib, is that what you are referring to? Sorry to be so stupid. How/where
do I put it?