문제

Is there a way to execute the method of a class after the deployment of my EAR?

In the EAR there is no WebProject.

I know the possibility of a ServletContextListener in a WebProject but i'd like to configure it in the EAR or in an EJB-jar if there is a way.

도움이 되었습니까?

해결책

There are no post-deploy options, I'm answering the question assuming you'd like to run some logic when your server starts, after deployment.

You may use Startup Beans, which is a WebSphere programming extension.

A little warning if you're planning to migrate to a more recent version (like WAS 8 or 8.5); this feature (startup beans) became a part of EJB 3.1 specification, so all servers supporting this specification level, including WebSphere, already have this functionality as specified, so this feature is deprecated and you shall prefer EJB3.1 specified solution.

다른 팁

My understanding of the question:

Is there a way to execute the method of a class after the deployment of my EAR?

is that you want to have a means of executing a method right or soon after an admin deploys an application regardless of its type and contents. My understanding of your needs is that you want it to work for cases when your application is only installed and has not been started yet which excludes the Java EE API like servlets with -1, ServletContextListeners or Startup Beans. If that's correct, read on.

I think you may want to use JMX as a means of administering WebSphere Application Server from your custom clients.

According to Developing an administrative client program:

4 Register for events.

In addition to managing resources, the JMX API also supports application monitoring for specific administrative events. Certain events produce notifications, for example, when a server starts. Administrative applications can register as listeners for these notifications. The WebSphere Application Server provides a full implementation of the JMX notification model, and provides additional function so you can receive notifications in a distributed environment. For a complete list of the notifications emitted from product MBeans, refer to the com.ibm.websphere.management.NotificationConstants class in the MBean API documentation.

I think that it merits attention and in fact answers the question.

Looking at the javadoc of com.ibm.websphere.management.NotificationConstants you may find the TYPE_APPMANAGEMENT_INSTALL constant which is

Notification type for application installation events

While I haven't tried it out myself yet, I think the WebSphere MBeans and JMX Notification is the way to go.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top