0

In package B, I want to access config files in package A, the package A is not at my local, and I do not want to add A as my dependency, how can I do this in Java? and how do I pass in this package A? Is that even possible to do so?

My use case is: I want to access folder X in package A at run time, and this X must exist in all A. This A is not at my local, and I do not know who will this A be ahead of time.

Ashley
  • 441
  • 1
  • 5
  • 8

1 Answers1

0

Packages are not more then directories in the classpath. so the package com.mycompany.someapp.services translates to com/mycompany/someapp/services.

Now consider how to access a file on the classpath (e.g. like here). Accessing a file from another package is just accessing it from another directory.

Jens Baitinger
  • 2,230
  • 14
  • 34
  • My use case is I want to access this A at run time, so I do not know which package I will access ahead of time. – Ashley Apr 12 '21 at 16:32
  • So how do you know which file you want to access? – Jens Baitinger Apr 12 '21 at 16:33
  • There is a folder in that package that I want to access, and I know this folder must exist, but I do not know who will this A be. – Ashley Apr 12 '21 at 16:35
  • and I checked the link you posted, it looks like the file has to be local for the getResourceAsStream() to work, but my use case is this A is not at my local. – Ashley Apr 12 '21 at 16:37