Re: Help with -classpath and packages
- From: Sigmund Hansen <sigmunha@xxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 18:03:42 +0200
dlarsson wrote:
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-?
*snip*
---
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.
---
Well, the Car.java file should really be placed inside a directory called com/example/rentalcar
This is why it tells you to place it in the correct subdirectory,
or at least I think it is.
Usually you'd have a structure sort of like this:
projectdir/src/com/example/rentalcar/Car.java
projectdir/build/com/example/rentalcar/Car.class
When compiling from the src dir, just set the -d to ../build (backslash on windows, obviously).
If this doesn't work then I don't know,
I'd recommend you use NetBeans or Eclipse to do your projects though, it would simplify these tasks a lot.
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
Obviously because there's no subdirectory com/example/rentalcar
.
- Follow-Ups:
- Re: Help with -classpath and packages
- From: Fergus Gibson
- Re: Help with -classpath and packages
- References:
- Help with -classpath and packages
- From: dlarsson
- Help with -classpath and packages
- Prev by Date: locale specific input
- Next by Date: can't fully unload a URLClassLoader
- Previous by thread: Re: Help with -classpath and packages
- Next by thread: Re: Help with -classpath and packages
- Index(es):
Relevant Pages
|
|