How to change context-root for enterprise applicat

2019-09-20 13:31发布

问题:

We have third party web based enterprise application, which is deployed on weblogic server and can be accessible using

http://hostname:port/myApp

But, due to some reason, we wanted to change context-root for this application, so that it must be ONLY accessible using

http://hostname:port/newApp

So, to achieve this, we tried changing application.xml

<?xml version = '1.0' encoding = 'utf-8'?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
   <display-name>myApp</display-name>
   <module>
         <web>
            <web-uri>myApp.war</web-uri>
            <context-root>newApp</context-root>  // changed from myApp to newApp
         </web>
   </module>
</application>

But, while deploying this application on weblogic server, we are getting following error.

weblogic.management.DeploymentException: The application myApp contains a SubDeploymentMBean with a name myApp however there is no module in the application with that URI or context-root.

On the other hand, if we keep both context-root as shown below application.xml file, then it gets deployed successfully and also able to access application using both context-root.

<?xml version = '1.0' encoding = 'utf-8'?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
   <display-name>myApp</display-name>
   <module>
         <web>
            <web-uri>myApp.war</web-uri>
            <context-root>newApp</context-root>  // changed from myApp to newApp
         </web>
   </module>
   <module>
         <web>
            <web-uri>myApp.war</web-uri>
            <context-root>myApp</context-root>
         </web>
   </module>
</application>

Can anyone help me to resolve this issue ? Let me know, if additional information required.

==Edited==

I have added weblogic.xml file, but not sure, what I suppose to change in this file as pointed by @Hououin Kyouma in his/her answer.

<?xml version = '1.0' encoding = 'US-ASCII'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
   <session-descriptor> 
      <cookie-path>/myApp</cookie-path> 
   </session-descriptor>
   <container-descriptor>
       <prefer-web-inf-classes>true</prefer-web-inf-classes>
   </container-descriptor>
</weblogic-web-app>

回答1:

You cannot define a context root with a differently named war file in the application.xml

<module>
    <web>
        <web-uri>myApp.war</web-uri>
        <context-root>newApp</context-root>  // changed from myApp to newApp
    </web>
</module>

You must change above to

<module>
    <web>
        <web-uri>newApp.war</web-uri>    // changed from myApp to newApp
        <context-root>newApp</context-root>  
    </web>
</module>

You need to create the war with the new name. You will still need to change the weblogic.xml in the new war file, but as long as this question goes, above is what you need to do.



回答2:

Have you tried setting the context root in the weblogic.xml? https://docs.oracle.com/cd/E13222_01/wls/docs90/webapp/weblogic_xml.html#1073750

EDIT Trying adding it like mentioned in this https://community.oracle.com/thread/747158

<?xml version = '1.0' encoding = 'US-ASCII'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
 <context-root>/newApp</context-root>
<session-descriptor> 
  <cookie-path>/newApp</cookie-path> 
</session-descriptor>
<container-descriptor>
   <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>