隐藏jar文件中的类 [英] Hiding classes in a jar file
问题描述
是否真的不可能在jar文件中隐藏某些类?
Is it really impossible to hide some classes in a jar file?
我不希望允许直接实例化类以保持其更灵活。只有工厂(或外观)才能看到这个罐子。
I wanted not to allow direct instantiation of the classes to keep it more flexible. Only the factory (or a facade) should be visible of this jar.
除了创建两个项目之外还有其他办法解决这个问题吗?
(两个项目:第一个包含类(实现),另一个引用第一个并包含工厂;后面只引用第二个)
Is there any other way than solve this problem than creating two projects? (Two projects: the first one contains the classes (implementation) and the other one references to the first one and contains the factory; later only the second one will be referenced)
推荐答案
我认为如果您的公共工厂方法尝试返回隐藏的内容,您将遇到编译器失败或警告。
I think you will have either compiler failure or warning if your public factory method try to return something which is "hidden".
不,如果不重新实现自己的 ClassLoader
或使用OSGi或类似的东西,你就无法隐藏公共类。
No, you can not hide a public class without reimplementing your own ClassLoader
or using OSGi or anything similar.
您可以做的是将接口api与实现分开,例如有一个项目只包含接口和另一个包含implmentations的项目。但是,您仍然无法隐藏实现类。
What you can do is to separate interface api from the implementation, e.g. have one project which contains only the interfaces and another porject which contains the implmentations. However, you still cannot hide the implementation classes.
这篇关于隐藏jar文件中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!