Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Using javac when superclass and subclass are in different packages

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javac orange/Base.java
javac strawberry/Sub.java


Also, I guess you meant package strawberry, not package.strawberry.
 
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Success Well done.
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic