Search code examples
javafile-iojbossjava-ee-6

How to access a file from a different war which is in the same ear on a Java EE Server (JBoss)?


So following problem: We have a load balancer with n servers behind it. On each server there is a PDF project (war) installed in ear together with a pdf-builder project in the same earfile (different war). I now want to read a pdf from the other war.

The problem is: I don't know the IP address of the server I'm running on and using the dns lookup I might end on the different server through the loadbalancer. Furthermore there might be problems with the access / security constraints since the server itself is not a valid user who has rights to make accesses to the pdf file locations of the pdf war project.

Is there a way to obtain something like getResourceAsStream() which works across different modules / war files within an ear?


Solution

  • You can move the .PDFs to a separate jar (ie pdf-builder.jar) and put it into the .EAR In the manifest of your .WAR (META-INF/MANIFEST.MF) put this line:

    Class-Path: pdf-builder.jar
    

    Now you can load the .PDFs using your class loader. This is J2EE compliant.