[英]In JBoss application server, how do I make sure that all modules in a deployment use the same Classloader for a jar library?
I have a deployable ear that I'm deploying to a JBoss application server. 我有一个可部署到JBoss应用程序服务器的耳朵。 I am in the process of refactoring my code so that my entity classes are declared in a separate jar library that can be shared by the different modules in the ear.
我正在重构代码,以便在一个单独的jar库中声明我的实体类,该类库可以由耳朵中的不同模块共享。
However, I am now getting the following error: 但是,我现在收到以下错误:
java.lang.ClassCastException: model.project.Project cannot be cast to model.EntityBase
EntityBase
is a public abstract class. EntityBase
是一个公共抽象类。 Project
is a public class that extends EntityBase
. Project
是扩展EntityBase
的公共类。 Both classes have been moved to my new jar library. 这两个类都已移到我的新jar库中。 This error leads me to the conclusion that there is an issue with the classloader.
该错误使我得出结论,即类加载器存在问题。
My ear is structured as follows: 我的耳朵的结构如下:
myapp.ear
|
|--- webportal.war
|--- restapi.war
|--- dal.jar
My entities had been defined in the dal.jar which is used by the war libraries to access my database. 我的实体已在dal.jar中定义,战争图书馆使用它来访问我的数据库。 I have now removed the entities from the dal.jar and placed them in a separate model.jar.
现在,我从dal.jar中删除了实体,并将其放置在单独的model.jar中。 I have listed the model.jar as a dependency in the pom.xml for myapp.ear.
我已经将model.jar列为myapp.ear的pom.xml中的依赖项。 It is also listed as a dependency in the pom.xml files for webportal.war, restapi.war, and dal.jar.
它在webportal.war,restapi.war和dal.jar的pom.xml文件中也作为依赖项列出。 As a result the model.jar is now deployed in the
lib
directory within myapp.ear. 结果,现在将model.jar部署在myapp.ear的
lib
目录中。
Is my understanding of the cause of the ClassCastException correct? 我对ClassCastException的原因的理解正确吗? If so, how do I package my application to ensure that all of the classes in model.jar are loaded with the same classloader?
如果是这样,我如何打包我的应用程序以确保用相同的类加载器加载model.jar中的所有类?
It turned out to be a relatively simple solution. 事实证明这是一个相对简单的解决方案。 I modified the pom.xml files for webportal.war, restapi.war, and dal.jar by adding a
scope
tag with a value of provided
for the model dependency: 我通过添加
scope
标签为模型依赖项provided
了一个值来修改webportal.war,restapi.war和dal.jar的pom.xml文件:
<dependency>
<groupId>myproject</groupId>
<artifactiId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
I then modified the pom.xml for myapp.ear by adding a dependency to model.jar with no scope tag (this will give the dependency the default scope which I believe is compile
): 然后,我通过将没有范围标记的依赖项添加到model.jar来修改myapp.ear的pom.xml(这将为该依赖项提供我认为是
compile
的默认范围):
<dependency>
<groupId>myproject</groupId>
<artifactiId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.