Okay folks, I thought I was doing something very, very simple,
but I cannot seem to get this to work at all.
Can anyone identify what I am doing wrong here-?
_________________________________
1. I have a class called "Car" that defines a package with
the statement: package com.example.rentalcar;
2. Then I have a test program called TestCar that imports
this package as follows:
import com.example.rentalcar.*;
3. Now, I then first compile the Car package as follows
javac -classpath . -d . Car.java
This succesfully compiles Car.java and places the Car.class file
in the subdirectory ==> com/example/rentalcar relative to
my current working directory (where both source files originate
from).
So, I have a current directory and then the generated
com/example/rentalcar subdirectory with the "Car.class"
file placed there - by this compile statement.
So far so good.
4. Okay, now I want to compile the little test program
that has the corresponding import com.example.rentalcar.*;
statement in it and uses the "Car" class.
---
So I try this:
javac -classpath . TestCar.java
I get the error:
TestCar.java:8: cannot access Car
bad class file: .\Car.java
file does not contain class Car
Please remove or make sure it appears in the correct
subdirectory of the classpath.
---
If I try to use the fully qualified path to my current directory
javac -classpath C:\Derek\java TestCar.java
I still get the same error:
TestCar.java:8: cannot access Car
bad class file: .\Car.java
file does not contain class Car
Please remove or make sure it appears in the correct
subdirectory of the classpath.
---
Now if I try to use the fully qualified path to the package itself (I
know this shouldn't work)
javac -classpath C:\Derek\java\com\example\rentalcar TestCar.java
I get the error:
TestCar.java:2: package com.example.rentalcar does not exist
import com.example.rentalcar.*;
TestCar.java:8: cannot access Car
bad class file: C:\Derek\java\com\example\rentalcar\Car.class
class file contains wrong class: com.example.rentalcar.Car
---
Just what do I need to do-?
What the heck do I have to set classpath to in order to get the java
compilier to resolve the import com.example.rentalcar.* statement
properly
in this TestCar program-?
I can't seem to feed anything to -classpath to make it work.....
What did I do wrong (and how do compile TestCar) -?
I appreciate all helpful responses .....
- Derek
EMail:
de***********@comcast.net