In Java EE 5, there are many new and exciting features. For example, developers can specify annotations in Java files instead of putting metadata in deployment descriptors. In some cases, applications can be completely free of deployment descriptors. This simplifies the development of Jave EE applications. This blog describes two common troubleshooting scenarios for deployment in GlassFish.
- Runtime error due to annotations not correctly processed (if at all) during deployment.
In this case, even though one may go through deployment, there will be a runtime error. For instance, suppose you have the following resource injection
private @Resource(name="jdbc/__default") DataSource ds;
then, you will have aNullPointerExceptionwhen you try to access theds. Verify that the annotation is not processed by doing the following:- turn on deployment log to FINE in the domain during deployment time
In this case, you will see a FINE message in server.log as follows:
Annotation is not processed for this archive.
Solution:
- Make sure that standard deployment descriptor files,
such as
ejb-jar.xml,web.xml,application-client.xmlrefer to the correct version of the XML schemas in the ear/war/jar files before deployment as the Java EE platform spec requires that annotations are only processed if the deployment descriptor uses the latest schema.Deployment Descriptor Version of XSD ejb-jar.xmlejb-jar_3_0.xsdweb.xmlweb-app_2_5.xsdapplication-client.xmlapplication-client_5.xsd - If the descriptors mentioned above refer to the correct schema
versions, then please make sure that the full attribute is "false"
or not specified there as the Java EE platform spec indicates that annotations
are only processed if the deployment descriptors using the latest schema have
the full attribute either specified as "false" or not specified. For instance,
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" full="false" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
- If the above are correct and the annotation in application client
is still not processed, then please make sure that the application client jar
file has a
MANIFEST.MFcontaining aMain-Classentry pointing to the fully qualified name of the app client main class. Note that, in general, one can specify the application client main class as an appclient command line argument. But in cases with annotation, one needs to haveMANIFEST.MFwithMain-Classentry.
- turn on deployment log to FINE in the domain during deployment time
- A library jar file is incorrectly treated as app client jar in a
deployment descriptor free application. This is due to the fact that the
given library jar file has a
Main-Classentry inMANIFEST.MFfile. Note that even though the application may be able to deploy, it may not be as you desired. For instance, if the given ear does not have an app client jar, deployment may interpret a library jar as an app client jar. One can verify this in admin GUI.Solution:
- Include
application.xmland defined each module explicitly. In this case, the library jar is not mentioned inapplication.xml.
For instance,
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd>
<display-name>deployment-ejb30-ear-securityApp</display-name>
<module>
<ejb>deployment-ejb30-ear-security-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>deployment-ejb30-ear-security-web.war</web-uri>
<context-root>deployment-ejb30-ear-security</context-root>
</web>
</module>
<module>
<java>deployment-ejb30-ear-security-client.jar</java>
</module>
</application> - Or remove the
Main-Classentry inMANIFEST.MFif it is unnecessary for the library function properly.
- Include
Posted by Shing Wai Chan on February 13, 2006 at 07:15 PM PST #
Sun App Server 9
Hibernate 3.2
Mysql
I need to call a webservice from another stateless bean (also exposed as a webservice). I am currently getting a NPE. I have "application.xml" in the ear file, and inside the ear are the EJB's inside a .jar file called "beans". Beans.jar has only a "persistence.xml". I have tried placing "application-client.xml" in the ear, and beans.jar to no avail. Any ideas?
Posted by Ben on June 06, 2006 at 04:19 PM PDT #
Posted by Mitesh on June 12, 2006 at 08:24 PM PDT #