Can I make WAR depend on JNDI entry in JBoss 5.1?

As part of the upgrade from JBoss 4.0.4 to 5.1, I am trying to run a WAR to deploy after a successful EAR deployment. JBoss 5.x does not support PrefixDeploymentSorter , as well as 4.x, which means that I have to use <depend> in WAR jboss-web.xml.

It seems that I cannot depend on the EAR itself , so I choose the last deployed EJB. This EJB provides the JNDI entry that WAR needs.

Here is the EJB when it is deployed when the WAR is not in the deployment directory:

2010-03-25 10:47:30,348 INFO [org.jboss.ejb3.session.SessionSpecContainer] (main) Starting jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3 2010-03-25 10:47:30,350 INFO [org.jboss.ejb3.EJBContainer] (main) STARTED EJB: my.package.MyFacadeBean ejbName: MyFacadeBean 2010-03-25 10:47:30,371 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Binding the following Entries in Global JNDI: my/MyFacade/local - EJB3.x Default Local Business Interface my-ear/MyFacadeBean/local-my.package.MyFacade - EJB3.x Local Business Interface 

And here the fragment depends on jboss-web.xml:

 <depends>jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3</depends> 

My problem: WAR starts deploying right after "STARTED EJB:", that is, before MyFacadeBean is bound to the JNDI, which causes the bean deployment to fail:

 2010-03-25 10:47:39,068 ERROR [my.facade.FacadeFactory] (main) MyFacade not bound 2010-03-25 10:47:39,069 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[my.host.no].[/]] (main) StandardWrapper.Throwable java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at my.freemarker.servlet.FreemarkerController.setupPojoServiceFactory(FreemarkerController.java:621) [...] Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: MyFacade not bound at my.facade.FacadeFactory.getFacade(FacadeFactory.java:61) 

After WAR has completed its deployment, MyFacade joyfully (mockingly?) Continues the deployment and associates the JNDI records.

If I warmly deploy WAR after deploying an EAR, everything works as intended.

I even thought that depending on the dummy EJB in the EAR, and using <module-order> strict </ module-order> in jboss-app.xml to make it load as the last module. But alas, JBoss 5.x also does not support this . Doh!

Is there a way to depend on the JNDI record itself? Are there other ways to solve this problem?

+4
source share
1 answer

Here you can achieve this on JBoss 5.1.x.

First add a file called aliases.txt to the META-INF your EAR. This file should contain only one line with an arbitrary name / identifier for your EAR. For example, if you have my-ear.ear, your META-INF/aliases.txt might contain "my ear." It just has to be something that will not conflict with any other aliases declared by other applications deployed on the same server.

Then add the jboss-dependency.xml file to your WAR's META-INF containing the following (subsituting "my-ear" for the alias you created above):

 <dependency xmlns="urn:jboss:dependency:1.0"> <item whenRequired="Real" dependentState="Create">my-ear</item> </dependency> 

This will ensure that the EAR is deployed before the WAR.

In addition, if you try to deploy a WAR without the presence of an EAR, JBoss will log an explicit deployment error message informing you of the missing dependency.

+2
source

Source: https://habr.com/ru/post/1305086/


All Articles