• Post Reply Bookmark Topic Watch Topic
  • New Topic

about javac -classpath  RSS feed

 
s sivaraman
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i've a question on how to use javac -classpath.

here's what i've tried..
i`ve an abstract class Fruit.class in a package
com\eat\Food
in the directory
D:\j\excercise\com\eat\Food(after the class is compiled)


and i've a class apple.java in a package implements Fruit.class
Food
in the directory
D:\j\excercise\


while i tried to compile the apple.java class

D:\j\excercise>javac -d . -classpath "\com\eat\Food" Apple.java
Apple.java:2: error: package com.eat.Food does not exist
import com.eat.Food.Fruit;
^
Apple.java:3: error: cannot find symbol
class Apple extends Fruit
^
symbol: class Fruit
2 errors

D:\j\excercise>javac -d . -classpath .\com\eat\Food Apple.java
Apple.java:2: error: package com.eat.Food does not exist
import com.eat.Food.Fruit;
^
Apple.java:3: error: cannot find symbol
class Apple extends Fruit
^
symbol: class Fruit
2 errors


if i'm right, i'm not using -classpath option right
help me with that

thank you
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like Apple.java has a package statement but isn't in the directory that would be expected of that type of package.



This expects the file will be in com\eat\Food.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-classpath "\com\eat\Food"

That isn't correct.
Your classpath should point to the root directory, that is the directory containing the "com" folder.
The full name of the Food class is com.eat.Food, which maps to the directory structure com/eat/Food, which is what the compiler looks for.
 
s sivaraman
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:It looks like Apple.java has a package statement but isn't in the directory that would be expected of that type of package.



This expects the file will be in com\eat\Food.


here is the sample code



and i checked that the fruit.class file is in the com\eat\Food\Fruit.class
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave has given you the correct answer. Your classpath should point to D:\j\exercise.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!