Is there a way to detect when a war file is successfully loaded by Wildfly and cause some code to execute?
You have a few options.
If you're leveraging CDI, you can add an observer method for @Observes @Initialized(ApplicationScoped.class) Object o
If you're leveraging EJBs, you can have a @javax.ejb.Singleton @javax.ejb.Startup
with a @PostConstruct
method that does initialization. Here are two example implementations.
// using a CDI object
@ApplicationScoped
public class SomeStartupBean {
public void initOnStartup(@Observes @Initialized(ApplicationScoped.class) Object obj) {
// do your start up logic here
}
}
or
// using an EJB
@Singleton
@Startup
public class SomeStartupSingleton {
@PostConstruct
public void initOnStartup() {
// do your start up logic here
}
}