1

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 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.

4

2 回答 2

2

不幸的是,Tomcat 通过文件名加载战争的方式是一个棘手的限制。

我使用了一种略有不同且特定于操作系统的方法:“符号链接”。这不是一个直接的答案,但无论如何可能会帮助你。

注意事项:

  1. 我使用 Linux,但这
    在 Windows Vista 和
    Windows 7 中也是可能的。
  2. 使用这种方法使用战争仍然很尴尬。Wars 是 zip 文件,因此最好将您的 war 解压缩到一个以
    版本命名的文件夹中。

解决方案:

从 myapps 文件夹到 webapps 文件夹中创建符号链接(如文件系统上的虚拟目录)。

  • 这将启用“coolName”、“coolName-v2”等。
  • 每个 webapp 都可能保存在文件系统中的不同位置
  • 您只需删除和重新添加指向不同目标的符号链接即可轻松“回滚”或“升级”(确保在切换时“停止”webapp)

Linux:

ln -s target_name link_name

维斯塔/Windows 7:

mklink link_name target_name

这样,您仍然可以使用 c:\tomcat7\webapps\ ,但指定符号链接如下:

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

(注意:对于战争,你需要先解压缩战争)

高温高压

于 2011-05-10T22:42:59.573 回答
0

您想要设置 Host 条目的 appBase 参数的权利。这是一个讨论在 Windows 下需要什么的上一个问题:Windows 下的 Apache Tomcat:更改 webapps 默认目录

至于如何更改应用程序的名称,在 META-INF 目录中添加一个 context.xml:Separating war application name from war file name

于 2011-05-10T22:13:32.137 回答