title: JBoss 7 Multiple root context web applications
body: <p>I need to configure two websites: www.foo.com and www.bar.net on my Apache2+ JBoss7.1 environment.</p>
  
  <p>Apache sites configuration example (they're similar each other, except for site name) : </p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerAdmin     foo@bar.com
          ServerName      www.foo.com
  
          DocumentRoot /var/www/foo
          &lt;Directory /&gt;
                  Options FollowSymLinks
                  AllowOverride None
          &lt;/Directory&gt;
          &lt;Directory /var/www/foo&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride None
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  
          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
          &lt;Directory "/usr/lib/cgi-bin"&gt;
                  AllowOverride None
                  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                  Order allow,deny
                  Allow from all
          &lt;/Directory&gt;
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
          LogLevel warn
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  
          SetEnvIf Request_URI "/photos/*" no-jk
          JkMount / ajp13
          JkMount /* ajp13
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>In JBoss standalone.xml I have:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false"&gt;
              &lt;connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/&gt;
              &lt;connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/&gt;
              &lt;virtual-server name="default-host" enable-welcome-root="false" default-web-module="bar"&gt;
                  &lt;alias name="localhost"/&gt;
                  &lt;alias name="www.bar.net"/&gt;
              &lt;/virtual-server&gt;
              &lt;virtual-server name="foo" enable-welcome-root="false" default-web-module="foo"&gt;
                  &lt;alias name="www.foo.com"/&gt;
              &lt;/virtual-server&gt;
          &lt;/subsystem&gt;
  </code></pre>
  
  <p>While both apps have jboss-web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jboss-web&gt;
      &lt;security-domain&gt;java:/jaas/foo&lt;/security-domain&gt;
      &lt;context-root&gt;/&lt;/context-root&gt;
  &lt;/jboss-web&gt;
  </code></pre>
  
  <p>Deploying foo.war results in:</p>
  
  <p>INSTALL: Failed to process phase INSTALL of deployment "foo.war"</p>
  
  <blockquote>
    <p>Caused by: org.jboss.msc.service.DuplicateServiceException: Service
    jboss.web.deployment.default-host./.realm is already registered</p>
  </blockquote>
  
  <p>What's the right configuration? Where is the error?</p>