Make deployment fail with customized error in Glassfish 3.1

507 views Asked by At

By throwing an exception in the @PostConstruct marked method in a @Startup marked bean, I am currently able to give a warning message when deploying the application on a Glassfish 3.1 server. However, it remains deployed (so it's in the list of applications) and the error message is a rather vague one, instead of the message given with the exception.

I wish to make the deployment fail completely, and give an appropriate message, to indicate what went wrong exactly. Is this doable from standard Java EE without customizing the Glassfish server? And if so, how?

The current setup is one with a Domain Application Server and two instances.

The current given message is the following

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.

Example of code being used in the @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 occurs in case of a RuntimeException

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

There are 1 answers

1
Athi On

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

hers a simple tutorial how to do it:

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

i was using this one but its for glassfish4

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