• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Package not found

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is it not recognizing the package?

p.s ClassA:


1.png
packages and files
packages and files
2.png
ClassB
ClassB
3.png
error
error
 
Marshal
Posts: 80617
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please navigate to the root folder where both packages would appear if you use ls. [edit]That means the OCP folder.
 
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are in the packageb folder,  the javac command needs a way to find the packagea folder.  I believe the -cp option can do that. For example:
javac -cp <path-to-folder-holding-packagea> ClassB.java
 
Bartender
Posts: 245
7
Android Python Oracle Postgres Database Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using plain javac the default classpath contains the work directory where javac is executed.

For production you should look into some build tool like Maven.

Example:

In directory java_packs you have the two source files located


Compile the packageb/B.java


After that javac create both class files since its able to resolve the dependency inside packageb.B


Execute the code inside java_packs


... or provide java with an explicit class path that contains java_packs:
 
Campbell Ritchie
Marshal
Posts: 80617
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:. . . I believe the -cp option can do that. . . .

Yes, it can.
 
Maria Isabel
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys!

The solution from Norm Radder using cp from packageb folder worked:


And the one suggested by Roland Mueller worked as well:
in OCP folder I've run:

 
Campbell Ritchie
Marshal
Posts: 80617
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maria Isabel wrote:Thank you guys!  . . .

That's a pleasure
reply
    Bookmark Topic Watch Topic
  • New Topic