You don't need to use MBeans. In the Servlet 2.3 spec, ServletContextListeners were introduced. Implement one of those and enter it an a war's web.xml file. Then add this war file to your ear that also contains your ejb-jar files (if you need more than just a web app). Then, you can trigger startup from the contextInitialized() method and shutdown on the contextDestroyed() method. This is a standard J2EE way of doing startup/shutdown hooks of J2EE applications, and is therefore appserver agnostic. Hope this helps.
Oh yeah. If you can't use Servlet 2.3 spec, you can use a similar (though not as elegant) mechanism in 2.2. Write a Serlvet instead of a ServletContextListener, and do your startup/shutdown code in the init()/destroy() methods, respectively. Then in web.xml, register the servlet *and be sure to add* a <load-on-startup>1</load-on-startup> element (the # doesn't really matter unless you want to order it with other servlets).
This should work in most of the cases except when the ejbs need something initialized during server startup. The basic JBoss deployment order is
"sar", "service.xml", "rar", "jar", "war", "wsr", "ear", "zip",
which means my jars are initialized b4 the war.
But contextinitialized and contextDestroyed should work most of the time.
I don't understand. Put your ejbs in an ejb-jar, then put the ejb-jar in the same ear as the war. JBoss deploys the ejb-jar in the ear before the war. When the war gets deployed, then you can look up your ejbs and do your initialization. All this happens before an end user can access anything. Am I not understanding you?
> You don't need to use MBeans. In the Servlet 2.3
> spec, ServletContextListeners were introduced.
> Implement one of those and enter it an a war's
> web.xml file. Then add this war file to your ear
> that also contains your ejb-jar files (if you need
> more than just a web app).
Well, I have tried this but it seems it does work under Jboss 3.2.1. The context is started but the listeners are actually not notified.
Anyone experienced the same behaviour?
Thanks in advance.
1) Make sure you have the appropriate listener tag in web.xml.
2) Make sure your web.xml is referring to the servlet 2.3 spec in the dtd line at the top, NOT 2.2.
3) Make sure your listener class ended up in your war file in the correct place, with the packaging matching that noted in your web.xml listener tag.
4) Check jboss' logs for errors.
5) If doing the above 4 things doesn't help you, post your web.xml file, and maybe a skeleton of your listener class.
I'd like to know how I need to organize my classes and .jar files.
I have a startup class A.class, that is used in user-service.xml for automatic startup. That means that I need to put my .jar file containing A.class into jboss-home\server\default\lib directory. Do I ALSO need to put it into jboss-home\server\default\deploy directory? Or just in one place - jboss-home\server\default\lib?
This class uses class B.class. Where should the .jar file, containing B.class, be located?
Should it be located in jboss-home\server\default\lib or in jboss-home\server\default\deploy? Or in both?
Basically, .jar files with what exactly classes should be located in jboss-home\server\default\lib and .jar files with what exactly classes should be located in jboss-home\server\default\deploy?
Another question. I could have just one combined .jar file with all classes, located in both directories. Can I split it somehow? Am I allowed to have several .jar files under jboss-home\server\default\deploy? Under jboss-home\server\default\lib?
Can I split it to several .jar files? Where exactly do I put them? In both places?
For instance, I split it to two .jar files. Do I need to put both into both places?
Can I put several classes into several different .jar files? Like if I put A.class into both B.jar and C.jar into jboss-home\server\default\deploy, will I have any problems? Like trying to redeploy certain things twice? Like EJBs or Message Driven Beans?
Can you give me any explanations on those questions? I am definitely doing something wrong. At this point the only way I succeed is to put everything into ONE .jar file, and put it into both directories. I can live with it, but that is not what I want.
I do not want to duplicated files unnecessarily into two directories, and I do not want conflicts between different files, between EJBs and MDBs. But I want all my EJBs and MDBs to be deployed correctly. At the same time I want to put as small amount of files as possible into jboss-home\server\default\lib directory (moving the rest to jboss-home\server\default\deploy), and I also want to split my .jar file in jboss-home\server\default\deploy directory into several .jar files, related to different packages.
Please give my some kind of guidelines to do that. Thanks