开发者

How do I create a virtual directory in Tomcat 7?

开发者 https://www.devze.com 2023-03-04 19:02 出处:网络
Tomcat is installed at C:\\tomcat7\\ but I want to deploy .war files in C:\\myapp\\xyz. For example, I might have C:\\myapps\\xyz\\MyApp.war and I should be able to reach it with the path http://local

Tomcat is installed at C:\tomcat7\ but I want to deploy .war files in C:\myapp\xyz. For example, I might have C:\myapps\xyz\MyApp.war and I should be able to reach it with the path http://localhost:8080/MyApp.

I tried appending this to the bottom 开发者_JS百科of c:\tomcat7\conf\server.xml

      <Host
          name="myapp"
          appBase="c:\myapps\xyz\"
          unpackWARs="true"
          autoDeploy="true">
      </Host>
    </Engine>
  </Service>
</Server>

This doesn't seem to work though as I don't see MyApp listed in the management console and I am not able to hit the URL. What else do I need to do?

Also, slightly unrelated but, how can I not have the name of the war file tied to the context name or URL path? For example, I want http://localhost/coolName to point to C:\myapps\xyz\MyApp.war.


Unfortunately the way Tomcat loads a war by filename is a tricky limitation.

I use a slightly different & OS-specific approach: "Symbolic Links". This isn't a direct answer, but may help you out anyway.

Caveats:

  1. I use Linux, but this is
    also possible in Windows Vista &
    Windows 7.
  2. using wars is still awkward using this method. Wars are zip files, so best to unzip your war into a
    version-named folder.

Solution:

Create symbolic links (like a Virtual Directory on the filesystem) from your myapps folder into the webapps folder.

  • This enables "coolName", "coolName-v2", etc.
  • each webapp could potentially be kept in different places in the filesystem
  • You can easily 'roll back' or 'upgrade' just by removing and re-adding symbolic links to different targets (make sure to "stop" the webapp while switching)

Linux:

ln -s target_name link_name

Vista/Windows 7:

mklink link_name target_name

In this way, you can still use c:\tomcat7\webapps\ , but specify symbolic links as follows:

mklink c:\tomcat7\webapps\coolName\ c:\myapps\xyz\webapp123\

(Note: For wars, you'd need to unzip the war first)

HTH


Your right in that you want to set the appBase paramete of the Host entry. Here is a previous question that discusses what it takes under windows : Apache Tomcat under Windows: Changing webapps default directory

As for how to change name of the app add a context.xml in the META-INF directory: Separating war application name from war file name

0

精彩评论

暂无评论...
验证码 换一张
取 消