简体   繁体   English

如何在context.xml中设置上下文路径

[英]How to set context path in context.xml

I have to deploy my app.war file in tomcat 7. The .war file name is followed by its version no. 我必须将我的app.war文件部署在tomcat 7中。.war文件名后跟版本号。 Here I need to set up a context path, so that the actual url will contain only the app name(without version no). 在这里,我需要设置一个上下文路径,以便实际的URL仅包含应用程序名称(无版本号)。

My requirement is that, there should be no edit in server.xml. 我的要求是,server.xml中不应有任何编辑。

My context.xml is as follows. 我的context.xml如下。

<?xml version='1.0' encoding='utf-8'?>
<Context path="/app" docBase="app-1.0" debug="0" reloadable="true">

    <!-- Defines links to JNDI Data Sources -->
    <!-- Thus the server determines database connection. -->

    <ResourceLink
            name="..."
            global="..."
            auth="Container" type="javax.sql.DataSource"/>

    .....
    .....

</Context>

The context.xml is placed inside the war at /META-INF folder. context.xml放在war中的/ META-INF文件夹中。 Can anyone tell me where am i wrong. 谁能告诉我我在哪里错。

All the elements are in the docs : http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming 所有元素都在文档中: http : //tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

For your use case, you could do try : 对于您的用例,您可以尝试:

  • change your version number format (from app-1.0.0.war to app##1.0.0.war for instance) 更改版本号格式(例如,从app-1.0.0.war更改为app ## 1.0.0.war)

  • place your war in another folder and create a app.xml in $catalina.base/conf/Catalina/ which contains : <Context path="/app" docBase="/path/to/app-1.0" debug="0" reloadable="true"> 将您的战争放置在另一个文件夹中,并在$catalina.base/conf/Catalina/创建一个app.xml,其中包含: <Context path="/app" docBase="/path/to/app-1.0" debug="0" reloadable="true">

  • avoid having your war with version number 避免与版本号发生冲突

Had a similar problem and it took me a long time to find the solution. 遇到类似的问题,我花了很长时间才找到解决方案。 It's on the tomcat site but it's difficult to find. 它在tomcat网站上,但很难找到。 This is what I did. 这就是我所做的。

Your war file will be deployed to a folder under %CATALINA_BASE%. 您的war文件将部署到%CATALINA_BASE%下的文件夹中。 I put mine in a folder called deploy. 我把我的放在一个名为deploy的文件夹中。 (%CATALINA_BASE%/deploy) (%CATALINA_BASE%/部署)

You'll create an XML file with the path to your war file above and place it in %CATALINA_BASE%/conf/Catalina/localhost. 您将使用上面的war文件的路径创建一个XML文件,并将其放置在%CATALINA_BASE%/ conf / Catalina / localhost中。 The name of the xml file will become your context root. xml文件的名称将成为您的上下文根。 If the name of your war file is app1.2.war and you want your context root to be /app you're create app.xml: <?xml version='1.0' encoding='utf-8'?> <Context docBase="C:\\tomcat7\\Servers\\server-app\\deploy\\app1.2" reloadable="false"/> (My deployment is on Windows, you'll obviously have to adjust for a different OS.) 如果war文件的名称为app1.2.war,并且您希望上下文根为/ app,则您将创建app.xml: <?xml version='1.0' encoding='utf-8'?> <Context docBase="C:\\tomcat7\\Servers\\server-app\\deploy\\app1.2" reloadable="false"/> 1.0'encoding <?xml version='1.0' encoding='utf-8'?> <Context docBase="C:\\tomcat7\\Servers\\server-app\\deploy\\app1.2" reloadable="false"/> (我的部署在Windows上,显然您必须适应其他操作系统。)

Also, let's for whatever reason say you want your context root to be /foo/Bar/app, change the name of your xml to foo#Bar#app.xml. 另外,无论出于什么原因,让我们说您希望上下文根为/ foo / Bar / app,将xml的名称更改为foo#Bar#app.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM