views:

45

answers:

3

I'd like to be able to annotate a public class/interface in Java as @NonPublic, which would mean This interface is only to be used within this project, it is not part of the public API that this project exports.

This is common for projects that are composed of several jar files. Not all public classes/interfaces are meant to really be public outside of your jar.

Do you know of any tool/framework/plugin that does this?

+2  A: 

IMHO the package system in Java is one of the most broken things that exist.

I'm not familiar with any standard Java-level mechanism to do that, although it is probably easy to write a tool or compiler extension that will enforce it.

However, if you are using OSGi (Eclipse is written that way), one of its advantages is a system for specifying better package and module level restrictions.

Uri
+2  A: 

Without OSGi another common practice is the separate API from implementation.

You could separate classes required during compile time from the ones which are required during runtime. To prevent users of your library to have dependencies to implementation details.

myLibAPI.jar   
myLibImpl.jar
stacker
This is a very good design practice, thanks for the tip!
espinchi
+1  A: 

OSGi Bundle is the solution.

If you want to convert you Jar into an Eclipse Plug-in, you can use Eclipse RCP release. Right click on your project : Configure -> Convert to plug-in projects

lepnio