I have an EJB that uses additional resource files (textual template files placed in a directory called “templates”). I don’t know how to access the content of the “templates” directory from the Java EE application.
I’ve tried to place the directory as the “EarContent/templates” or “EarContent/APP-INF/lib/templates” folder in the EAR project. The directory is deployed into the weblogic domain as expected. (I was searching it in the file-structure of the weblogic domain.)
But when I want to access the files, all resource paths seem to be relative to the weblogic domain root directory, not relative to the deployed application. Thus
URL dirURL = this.getClass().getClassLoader().getResource("templates");
returns “file:/<domain_root>/templates”,
File file = new File("templates");
opens a file in “<domain_root>/templates” (if there is any).
How to access additional resource files correctly?
Edit: I have found that when I place the “templates” directory into the EAR project as “EarContent/APP-INF/classes/templates”, both the code pieces mentioned above find it. But the “classes” directory is not the right place to put the “templates” directory in… (At least because the IDE filters non-.class files out in this directory, and does not display it.)
Edit: I’ve been playing with it a bit. Using the FileMon I see that weblogic completely ignores directories specified in the MANIFEST.MF classpath. I’ve tried both the EJB and EAR manifests, and weblogic does not even try to look into the path specified in the manifest.
Manifest-Version: 1.0
Class-Path: APP-INF/
I’ve spent a lot of time by googling and experimenting, but I have found no other way than to place the directory into the <EarProject>/EarContent/APP-INF/classes/ folder. Another solutions, even when (vaguely) suggested in the weblogic documentation, like setting the Classpath in a MANIFEST.MF file, did not work.
I’ve tested also a possibility to place the template directory into a separate utility project. The template directory must be placed in the <Utility project>/src/ folder. However, in the development environment, the template directory is deployed as a regular directory, while when exported into an EAR, the template directory is packed into the utility project .jar. When deployed onto a Weblogic server, this .jar is not unpacked, so you cannot acces the template files as regular files, in particular you cannot enumerate them.