views:

1526

answers:

6

I have an EAR file that contains two WARs, war1.war and war2.war. My application.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<application version="5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"&gt;
  <display-name>MyEAR</display-name>
  <module>
    <web>
      <web-uri>war1.war</web-uri>
      <context-root>/</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>war2.war</web-uri>
      <context-root>/war2location</context-root>
    </web>
  </module>
</application>

This results in war2.war being available on http://localhost:8080/war2location, which is correct, but war1.war is on http://localhost:8080// -- note the two slashes.

What am I doing wrong?

Note that the WARs' sun-web.xml files get ignored when contained in an EAR.

A: 

http://localhost:8080// should still be a valid URL that is equivalent to http://localhost:8080/

I'd experiment with leaving the context-root of war1 blank (though I'm not sure if that's allowed). Or changing it to <context-root>.</context-root>.

Otherwise I'd have to say the generated URI is a bug on glassfish's part since I've never seen that using sun's.

Joseph Daigle
It's not unfortunately. http://localhost:8080/ gives Glassfish's default welcome srceen. An empty context-root uses the WAR name and a . simply does not work. :(
Marius Marais
A: 

This seems to me as a bug in the glassfish application server. It should work as it is already defined your application.xml file.

Maybe you could try the following:

<context-root>ROOT</context-root>
Panagiotis Korros
Tried it; WAR available on /ROOT :)
Marius Marais
+2  A: 

This does seem to be a bug / feature.

You can set Glassfish to use a certain web application as the root application, ie. when no other context matches, but the application then still thinks it's running on the original context and not on the root.

My solution is to run the first WAR on /w and use Apache to redirect /whatever to /w/whatever using a RedirectMatch. Not very pretty, but it solves the problem (kinda).

RewriteEngine On
RedirectMatch ^/(w[^/].*) /w/$1
RedirectMatch ^/([^w].*) /w/$1
Marius Marais
A: 

Have you given it another try on a more recent version of Glassfish? (3.0.1 just came out).

I've been able to get a -single- WAR in an exploded EAR to deploy to http://localhost/ using Glassfish 3.0.1. Like you mentioned, sun-web.xml seems to be ignored (inside of exploded ears at least).

Jon
A: 

In Glassfish 3.0.1 you can define the default web application in the administration console: "Configuration\Virtual Servers\server\Default Web Module". The drop-down box contains all deployed war modules.

The default web module is then accessible from http://localhost:8080/.

jiriki
A: 

Thanks jiriki. The Perfect answer! Works in Galssfish 2.1.1 too!

Configuration> HTTP Service> Virtual Servers> server

or change default-web-module parameter in domain.xml

Greeno