0

I would like to set the context-root of the web application part of my enterprise application (bundled as an EAR). I added an "application.xml" file which looks like this:

<application>
    <module>
        <web>
            <web-uri>SearchResulter-war.war</web-uri>
            <context-root>/searcharoo</context-root>
        </web>
    </module>
</application>

The thing is, I have EJBs in the project as well. It seems that the Java EE 5/6 magic previously did not require me to include an "application.xml" file, and that was all good until I wanted to change the context-root. Is it an all-or-nothing proposition as far as defining your own goes? In other words, must I add an <ejb> element with the relevant info?

Rintoul
  • 823
  • 2
  • 13
  • 16

4 Answers4

5

Quoting the section 8.5.2 Deploying a Java EE Application of the Java EE Specification v6:

The deployment tool must first read the Java EE application deployment descriptor from the application .ear file (META-INF/application.xml). If the deployment descriptor is present, it fully specifies the modules included in the application. If no deployment descriptor is present, the deployment tool uses the following rules to determine the modules included in the application.

In other words, when providing an application.xml, you need indeed to include all modules in it.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
1

I cannot get to the jcp.org site to check the final draft of JSR316... which should have the definitive answer...

My best advice would be to create a 'complete' application.xml, though.

vkraemer
  • 9,864
  • 2
  • 30
  • 44
  • 1
    I think you're right. According to the spec: "The deployment tool must first read the Java EE application deployment descriptor from the application .ear file (META-INF/application.xml). If the deployment descriptor is present, it fully specifies the modules included in the application. If no deployment descriptor is present, the deployment tool uses the following rules to determine the modules included in the application." I should have looked at that first, I suppose. :( Thank you for your help! – Rintoul Jan 02 '10 at 07:40
1

First of all, you don't have to use application.xml. Since you have a war file, you can use the container specific deployment descriptor to define the context-root. For example, in WebLogic Server Administration Console doc, it reads,

"You can specify the context-root element in the weblogic.xml deployment descriptor for Web Applications that are packaged as a .war archive or exploded .war directory. If you package the Web Application as part of an Enterprise Application (.ear archive or exploded .ear), specify the context-root in application.xml. Note that the application.xml context-root takes precedent over the weblogic.xml value."

Or, in glassfish-web.xml (or sun-web.xml) for the case of Glassfish.

If you do decide to use the standard application.xml, the container would pick up the full list of modules from this descriptor. In other word, application.xml takes precedent over module-level descriptors. So yes, you would need to also include your ejb elements in your application.xml.

BJYC
  • 354
  • 2
  • 10
0

According to JSR316, context root must be specified in META-INF/application.xml, otherwise web module will acquire name of its deployment package stripped of .war extension.

Jarek Rozanski
  • 780
  • 1
  • 6
  • 13
  • If you decide to skip application.xml, you can modify context root name by application server specific configuration. You may then use EJB 3.1 and other JEE6 goodness within your WAR package. For example, in Glassfish 3, you can modify context root in WEB-INF/sun-web.xml. – Jarek Rozanski Jan 02 '10 at 11:27
  • Since I am using Glassfish v3, I did try the suggestion by jarekronzanski, but it didn't seem to work. I am using NetBeans as an IDE and am launching the application through some mechanism which I do not fully understand, so something could be going wrong there... – Rintoul Jan 02 '10 at 19:01
  • Can you try exporting WAR package from NetBeans and deploying it out of IDE? Check if in you WEB-INF/sun-web.xml you can find entry: /MY_NEW_CONTEXT_NAME – Jarek Rozanski Jan 02 '10 at 21:40