Deployment failed with modified error in Glassfish 3.1

By throwing an exception in a method marked with @PostConstruct in a @Startup marked with a bean, I am currently able to give a warning when deploying an application to a Glassfish 3.1 server. However, it remains expanded (which is why it is in the list of applications) and the error message is rather vague and not the message specified with the exception.

I want the deployment to fail and give an appropriate message to indicate what went wrong. Is this doable from standard Java EE without setting up a Glassfish server? And if so, how?

The current setup is with a domain application server and two instances.

The current given message is as follows

Warning Command succeeded with Warning
"http://localhost:4848/management/domain/applications/application/applicationname" created successfully. WARNING: Command _deploy did not complete successfully on server instance instance1: remote failure: Failed to load the application on instance instance1. The application will not run properly. Please fix your application and redeploy. Exception while shutting down application container : java.lang.NullPointerException. Please see server.log for more details. WARNING: Command _deploy did not complete successfully on server instance instance1: remote failure: Failed to load the application on instance instance1. The application will not run properly. Please fix your application and redeploy. Exception while shutting down application container : java.lang.NullPointerException. Please see server.log for more details.

      

Sample code used in @PostConstruct

@PostConstruct
public void init() throws ExceptionInInitializerError {
    throw new ExceptionInInitializerError("Don't deploy!");
}

      

also for

@PostConstruct
public void init() throws Exception {
    throw new Exception("Don't deploy!");
}

      

The same happens in case of a RuntimeException.

@PostConstruct
public void init() {
    throw new RuntimeException("Don't deploy!");
}

      

+3


source to share


1 answer


I think the way to "break" the deployment and throw an exception is to use the JavaEE SPI extension.

her simple tutorial how to do it:

http://blog.eisele.net/2010/01/jsr-299-cdi-portable-extensions.html



i used this one but for glass fish 4

http://www.byteslounge.com/tutorials/java-ee-cdi-extension-example

+2


source







All Articles