• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using javac when superclass and subclass are in different packages  RSS feed

 
John Mulholland
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, wondering if someone could help me with this. I have two classes :

In sourcefile Base.java (in directory named "orange")

In sourcefile Sub.java (in directory named "strawberry")

I can compile Base easily by javac Base.java. However, when I try to compile Sub I get an error "package orange does not exist".

(1) Is there a way I can organise the directories so that this will compile AS IS ?

(2) If not how can I arrange the -sourcepath or -classpath to make it compile and run ?

Any help would be greatly appreciated.

John
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac orange/Base.java
javac strawberry/Sub.java


Also, I guess you meant package strawberry, not package.strawberry.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must also navigate to the “parent” folder to those two folders so orange and strawberry are visible if you use the dir instruction (on Windows) or ls (On *nix).
 
John Mulholland
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys this worked. I wasn't in the parent dir when I was trying to use javac - I was (wrongly) trying to use javac directly in the separate sourcecode folders.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Success Well done.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!