This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I hope, somebody from you, guys will be able to help me.
I would like to make a code, which would be executed on application deployment or startup. Is there any listener of Java EE server, which would make it possible?
The reason, why I need this feature is, that I would like to generate some classes during runtime, using javassist and use them during application running. Am I even on right dirrection to do something like this?
I'm using Java EE 5. About app server I would like to be independent, because source, which I'm writing is primarily for framework, which we will use for different projects.
In the first place generated code, I would like to make will be for EJBs.
In Java EE 5, there isn't a way to trigger a EJB on application deployment. There is a way for doing this in Java EE 6 with @Singleton @Startup beans.
For Java EE 5, the easiest way to get similar functionality is to package your application as a .ear with a .war module (web) and a EJB module. You can then have a ServletContextListener which will be triggered when the web application is deployed.
Also, search for "startup" (without the quotes) in this EJB forum and you will find some interesting discussions (on page 1 and 2) related to this.
Joined: Nov 18, 2010
So, for features I would like to use, I have to switch to Java EE 6. But for now I will try to do workaround with .war module, as you suggested.