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?
No, that is not valid. An EAR file may contain other module-level archives, such as WAR, EJB JARs, RARs, or library JARs, but it may not contain other EAR files.
Static HTML files and JSP are stored at the top level of the WAR directory. The top-level directory contains the WEB-INF sub-directory which contains the following: Server-side classes (Servlets, JavaBean components and related Java class files) must be stored in the WEB-INF/classes directory.
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.
You need to provide absolute path to the file in order to access a resource which is not in current class path.
you can call
serverletContext.getRealpath("/");
will give the the path till the server node (context). From there you can navigate to the file.
One more way is, Jboss uses (or set) several environment variables while it bootstraps. You can use those properties in order to get the current node (like 'default'). Following two properties will give you the absolute path to current server node.
System.getProperty("jboss.server.base.dir") + File.separator + System.getProperty("jboss.server.name")
;
(Please use System.getenv('varname')
if getProperty don't work). From there you can navigate.
Here is the complete list of system varibles that jboss uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With