rns
rns

Reputation: 1091

Expose particular package from jar

Is it possible to access only few packages from jar file, and for remaining packages we can hide from them for accessing from jar file.

For instance,

enter image description here

I want to access classes from p1 package and hide all other classes of p2 and p3 package from jar file. While classes in p2 and p3 are public and are implemented in classes from p1 package?

Upvotes: 2

Views: 141

Answers (2)

Puce
Puce

Reputation: 38142

You will need some module system to reach this goal, eg.

  • OSGi (current de-facto standard)
  • NetBeans Module System (not very common outside NetBeans Platform applications)
  • Jigsaw (upcoming standard module system in Java SE 9)

Upvotes: 1

Pradeep Simha
Pradeep Simha

Reputation: 18123

No this is not possible with default JAR file. You have two options:

  • Mark private package as internal and document in such a way that client will not use, in document mention like "Classes under this package can change at any time" so clients won't use it, just like JDK does.
  • Another option is to use OSGi which helps for your requirements. More info here

Upvotes: 2

Related Questions