Qazi
Qazi

Reputation: 132

Adding multiple context roots to a single application

Can we add multiple context roots to one project in Java EE?

I tried this but not working for me:

<wls:context-root>/ayz</wls:context-root>
<wls:context-root>/abc</wls:context-root>

Upvotes: 2

Views: 11165

Answers (5)

SMR
SMR

Reputation: 11

One way of doing it in weblogis is..deploy the application as shared library.. Create another application (lets call dummy) with empty web.xml and weblogic.xml with <library-ref> and <context-root>(Using which you want to access the application) which refers to shared libray. Create as many as dummy applications if you want it refer with multiple context roots.

Upvotes: 0

Rich
Rich

Reputation: 865

As far as i know, in jboss terms, you can only have 1 per app. It can be defined in several ways (in this case) with a statless bean using ejb3 annotation:

@Stateless
@WebService(
    name = "MyService",
    targetNamespace = "http://myurl.co.uk/MyContext/MyService",
    serviceName = "MyService")
@WebContext(contextRoot = "/MyContext" , urlPattern = "/MyService")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@HandlerChain(file = "META-INF/jaxws-handlers-server.xml")
public class MyIface {

    // Inject the persistence layer
    @EJB(beanInterface=IPersistenceLayerBean.class)
    private IPersistenceLayerBean persistenceLayer;

    @WebMethod
    public Response doSomething() {
        return persistenceLayer.helloWorld();
    }

}

You can have several interfaces defined within an application, each with its own "urlPattern", but they must share the same "contextRoot", otherwise you'll see an error to that effect.

Upvotes: 0

abishkar bhattarai
abishkar bhattarai

Reputation: 7641

If you are using tomcat Go to conf\Catalina\localhost folder of tomcat .Add test1-server.xml and test2-server.xml.In both test1-server.xml and test2-server.xml file add following

<Context path="/test-server" docBase="D:\\pathtofilessystemwhere test-server islocated \test-server" />

The context path can be different for test1-server.xml and test2-server.xml when you run tomcat it will be loaded from two context path

Upvotes: 0

Uri Lukach
Uri Lukach

Reputation: 1121

Of course you can,

The how to, depends on the app. server/web container. For example in tomcat, if you open the /conf/server.xml you will see how to define a context, for example

<Context path="/hello" docBase="../../../../work/hello" >

path - /hello - is the web path
docBase - "../../../../work/hello - is the file system location

Most web containers will allow you to define a context simply by adding the web-directory under the ROOT directory as long as it complies with the web-directory standard.

But in most cases you will probably want to place the directory in different location and use the Context tag.

Upvotes: 0

dkaustubh
dkaustubh

Reputation: 454

One web application can only have one "context root". How you define it depends on what container you are using. For example in WebSphere you can define it in the application.xml.

<module id="Module_1332249637478">
  <web>
    <web-uri>XxxWeb.war</web-uri>
    <context-root>/xxx</context-root>
  </web>
</module>

Upvotes: 3

Related Questions