如何在 Tomcat 7 中创建虚拟目录?
Tomcat 安装在 C:\tomcat7\ 但我想将 .war 文件部署在 C:\myapp\xyz 中。例如,我可能有 C:\myapps\xyz\MyApp.war,我应该能够通过路径 http: //本地主机:8080/MyApp。
我尝试将其附加到 c:\tomcat7\conf\server.xml 的底部,
<Host
name="myapp"
appBase="c:\myapps\xyz\"
unpackWARs="true"
autoDeploy="true">
</Host>
</Engine>
</Service>
</Server>
但这似乎不起作用,因为我没有看到管理控制台中列出了 MyApp,并且无法访问该 URL。我还需要做什么?
另外,稍微不相关,但是,我怎么能不将 war 文件的名称与上下文名称或 URL 路径绑定在一起呢?例如,我希望 http://localhost/coolName 指向 C:\myapps\xyz\MyApp.war。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,Tomcat 按文件名加载战争的方式是一个棘手的限制。
我使用稍微不同的 &特定于操作系统的方法:“符号链接”。这不是直接答案,但无论如何可能会对您有所帮助。
注意事项:
也可以在 Windows Vista &
Windows 7.
战争是 zip 文件,所以最好
将你的战争解压成
以版本命名的文件夹。
解决方案:
创建从 myapps 文件夹到 webapps 文件夹的符号链接(如文件系统上的虚拟目录)。
“coolName-v2”等
可能会被保留在
文件系统中的不同位置
Linux:
Vista/Windows 7:
以这种方式,您仍然可以使用 c:\tomcat7\webapps\ ,但指定符号链接如下:(
注意:对于 wars,您需要先解压 war)
HTH
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:
also possible in Windows Vista &
Windows 7.
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.
"coolName-v2", etc.
could potentially be kept in
different places in the filesystem
Linux:
Vista/Windows 7:
In this way, you can still use c:\tomcat7\webapps\ , but specify symbolic links as follows:
(Note: For wars, you'd need to unzip the war first)
HTH
您有权设置 Host 条目的 appBase 参数。这是讨论 Windows 下的前一个问题: Apache Tomcat under Windows:更改webapps默认目录
至于如何更改应用程序的名称,请在META-INF目录中添加一个context.xml:将war应用程序名称与war文件名分开
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