0

I have deployed a application in Apache tomcat. Suppose name of project is abc (or deployed from abc.war).

I access it using url :=> http://localhost:8080/abc/

But I want to redirect or have aliases for web app. like

http://localhost:8080/abc/ http://localhost:8080/abc1/ http://localhost:8080/abc2/ http://localhost:8080/abc3/

All the above reference to same Web-app. How can I do it and I do not want to copy paste the folder as many times and renaming it.

~Thanks

dinesh028
  • 2,137
  • 5
  • 30
  • 47
  • [possible duplicate](http://stackoverflow.com/questions/11721966/how-can-i-map-multiple-contexts-to-the-same-war-file-in-tomcat) – A4L May 24 '13 at 09:07

2 Answers2

0

The best solution is not using a warfile. Copy all the content into a specified directory (i.e. \user\abc) and then you can either configure all the contexts in two ways.

  • one xml for every context to map, by putting it into your: %CATALINA_HOME%\conf\Catalina\localhost. Keep in mind that the name of the xml file will be the mapping of your webapp, but you can redefine it with the path attribute inside the xml. In your case you have to produce abc.xml, abc1.xml, abc2.xml and their content should be something like:

    abc.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <Context docBase="\user\abc" path="abc" reloadable="false"/>
    

    abc1.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context docBase="\user\abc" path="abc1" reloadable="false"/>
    
  • you can edit directly the %CATALINA_HOME%\conf\server.xml by inserting, inside the <Host ...> tag, the contexts definitions, something like this:

    <Host ...>
        <Context docBase="\user\abc" path="abc" reloadable="false"/>
        <Context docBase="\user\abc" path="abc1" reloadable="false"/>
    </Host>
    

If you need to provide database datasource information to a context, just add the tag Resource to the context definition itself (either in an xml file or in server.xml),here you go with a sample:

<Context docBase="\user\abc" path="abc" reloadable="false">
    <Resource auth="Container" description="DataSource"
        driverClassName="oracle.jdbc.driver.OracleDriver"
        maxActive="4"
        maxIdle="2"
        maxWait="5000"
        name="jdbc/myJNDIname"
        password="mypass"
        type="javax.sql.DataSource"
        url="jdbc:oracle:thin:@host:port:SID"
        username="myuser"/>
</Context>

If you need this last part, just use it, obviously, for every context you like to duplicate.

Hope it helps.

lucasvc
  • 767
  • 1
  • 11
  • 35
  • This won't solve the problem! He'll deploy the app multiple times in an exploded fashion. He requires URL rewrite or Redirect Permanent. – Michael-O May 31 '13 at 22:29
  • Yeah sure, in that way the weapp is deployed more than 1 time so you have to evaluate all the efforts occurring in this case. If it's not a lightweight webapp, or it needs to be a permanent, clean solution, the best way is an Apache managing the contexts in front of the appserver. – grimpressive Jun 03 '13 at 10:33
0

the easiest way is create soft link directory of the app, like this

ln -s $PWD/abc $PWD/abc1
ln -s $PWD/abc $PWD/abc2
ln -s $PWD/abc $PWD/abc3