简体   繁体   English

Java方法范围问题

[英]Java method scope issue

I have two distinct archives within in the same .ear deployed on an application server. 我在应用程序服务器上部署的同一.ear中有两个不同的存档。 One is a .war and one is a .jar. 一个是.war,一个是.jar。 I have the same package names in both archives 两个档案中的软件包名称相同

in .jar archive>> com.me.dummy.MyClass
in .war archive>> com.me.dummy.CLientClass

In com.me.dummy.MyClass I have a protected method called proctectedMethod() . com.me.dummy.MyClass我有一个称为proctectedMethod()的受保护方法。 In com.me.dummy.CLientClass i invoke com.me.dummy.MyClass.proctectedMethod() . com.me.dummy.CLientClass我调用com.me.dummy.MyClass.proctectedMethod()

This does not cause any compile time issues, but at runtime it throws accessError 这不会引起任何编译时问题,但是在运行时会引发accessError

java.lang.IllegalAccessError

Why does this only throw the IllegalAccessError at runtime? 为什么这只会在运行时抛出IllegalAccessError

Thanks 谢谢

I believe that this happens because your application server loads web application using separate class loader. 我相信这是因为您的应用程序服务器使用单独的类加载器加载了Web应用程序。 You should consult your app server documentation how to make it to use the same class loader for whole enterprise application. 您应该查阅您的应用服务器文档,以了解如何使整个企业应用程序使用相同的类加载器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM