0
votes

I have an EAR with a WAR and a lot of EJB-modules inside.

Each EJB-module has a file called "menu.js" (a JSON array) . I use that files to create an automatic menu configuration reading that JSON.

If I include the EJB-module in a new EAR, i bring the menus with it.

For example, a GeoDataModule has a menu entry called Country. In each EAR project where I want to use that module, I want to create all the menu entries required.

Actually I put these json object in a resource archive and I read it from the war.

What I want to do is to cicle throw all the EJB-modules and read the "menu.js" file. This procedure must be done in a class inside the war and the war is the same for all projects (the WAR has only some common ruotines, nothing specific for the EAR). So, the WAR don't know what are the ejb-modules included in the EAR.

How can I achieve that procedure? I need something like:

  1. list all the ejb-modules included in the ear;

  2. for each ejb module, read the menu.js file

1
I'm not sure that all the modules are available in the same ClassLoader, but you can try something like: getClass().getClassLoader().findResources("menu.js")Maurice Perry
How does the WAR module load EJBs with out prior knowledge of what EJBs are available?Steve C
@SteveC the WAR does not know what EJB is included, this is another point how what i want to do. Thanks, i've edited the answer with more informationDaniele Licitra
You might be able to fire a CDI event from an @Startup EJB in each module and @Observes it from the web module. It's not something I've ever tried though.Steve C

1 Answers

0
votes

Thanks to Maurice Perry's suggestion (in question comment), I've written this two line: i read all "the same name" files as reources.

Enumeration<URL> listResource = Thread.currentThread().getContextClassLoader()
                 .getResources("BwcMenuStandard.json");
while(listResource.hasMoreElements()){
   URL file = listResource.nextElement();
   LOG.log(Level.WARNING, "File found from thread: {0}",file.getPath());
}
Enumeration<URL> listResource2 = this.getClass().getClassLoader().getResources("BwcMenuStandard.json");
while(listResource2.hasMoreElements()){
   URL file = listResource2.nextElement();
   LOG.log(Level.WARNING, "File found from class: {0}",file.getPath());
}

I get the same results in the two way.

Now with the list of files, i'll open the file as stream and import it.