Many applications have a requirement that they want to automatically execute an application client archive(CAR) packaged as a part of enterprise application (EAR) when server starts up or an application is restarted. This is a Java EE 5 standard compliant alternative to Startup class about which I blogged about 2 and half years back!
In this article, I will outline steps to do this in OC4J.
- Develop and compile your application client class. This class must contain a main method that will be called by your server during startup.
- Create a META-INF/Manifest.mf file for the application-client, for example
- Create a deployment descriptor for the application client (application-client.xml) as follows:
- Create the application client archive (CAR) file for your startup class with the above Manifest and deployment descriptor.
- Create an EAR file for the application client module with the an OC4J-specific deployment descriptor orion-application.xml as follows:
<client-module path="startup-client.jar" start="true" user="anonymous" >
- Build your EAR and deploy your application with auto start set to "true" as follows in the server.xml:<application name="startup"
path="../applications\startup.ear" parent="default" start="true" >
Whenever your application is deployed or if you restart your server, the application client will be executed automatically!
Hope this helps!