简体   繁体   中英

Calling methods from one WAR file in another WAR file within the same application

I am using WebSphere 8.5

I will have 2 War files within one EAR file. I will have some code that would be common to both War files. I have tried to explain a possible structure below.

War1
   package P1
   Common-package C1 (*Dependent on P1)

War2
   package P2 (Needs to access C1)

I would like to keep the common package only in War1 and call it from War2. Seems like C1 is not accessible from War2 (class not found error). If I kept C1 outside both War files, C1 would be accessible to both War files. Since C1 is dependent on P1 I am not sure I can do that. Is there a way to access a common package in one War file from another?

If you don't need the isolation at all, WebSphere provides a setting to use a single class loader for an application (including the EAR and all WARs) - item #5 in this document: https://www.ibm.com/docs/en/was-nd/8.5.5?topic=loading-configuring-application-class-loaders

If your WARs are reliant on separate versions of some API, or if they require separate static variables, that won't work for you, but if not, that should get you what you need. You could also, of course, simply put the necessary shared package into both WARs, or move the common code to the EAR and also move/copy the dependencies along with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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