java 使用 Maven 时如何在 Tomcat 7.0 中将上下文路径设置为 root("/")

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26861999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:46:20  来源:igfitidea点击:

How to set context path to root("/") in Tomcat 7.0 when using Maven

javamaventomcatmaven-plugin

提问by Bogdan Timofeev

I hava a maven project, pom.xml contains tomcat plugin.

我有一个 maven 项目,pom.xml 包含 tomcat 插件。

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.2</version>
</plugin>

I've downloaded Tomcat 7, so I've got Tomcat directory (apache-tomcat-7.0.56). I tried three goals to run my project:

我已经下载了 Tomcat 7,所以我有 Tomcat 目录 (apache-tomcat-7.0.56)。我尝试了三个目标来运行我的项目:

tomcat7:run, tomcat7:run-war, tomcat7:run-war-only

tomcat7:run, tomcat7:run-war, tomcat7:run-war-only

My application is running at http://localhost:8080/projectname, if I run tomcat7:run-war, projectname-0.0.1-SNAPSHOT.warappears in the /target directory of my project.

我的应用程序正在运行http://localhost:8080/projectname,如果我运行 tomcat7:run-war, projectname-0.0.1-SNAPSHOT.war则会出现在我项目的 /target 目录中。

I want to run my application at http://localhost:8080/.

我想在http://localhost:8080/.

I know this question was asked before, but unfortunately those solutions didn't help me.

我知道之前有人问过这个问题,但不幸的是,这些解决方案对我没有帮助。

I tried both methods from the first answer of this.

我从this的第一个答案中尝试了这两种方法。

First method didn't work for me, after renaming war nothing changed, tomcat7:run-war-only requires war with name like projectname-0.0.1-SNAPSHOT.war.

第一种方法对我不起作用,重命名War后没有任何改变,tomcat7:run-war-only 需要名称为 projectname-0.0.1-SNAPSHOT.war 的War。

The second method changed nothing (I tried both

第二种方法没有任何改变(我都试过

<Context path="" docBase="projectname-0.0.1-SNAPSHOT" debug="0" reloadable="true"></Context>
and

<Context path="" docBase="projectname-0.0.1-SNAPSHOT" debug="0" reloadable="true"></Context>

<Context path="" docBase="projectname" debug="0" reloadable="true"></Context>)

I have also looked throw this, but I don't have <catalina_home>/conf/Catalina/localhost/directory in my Tomcat directory.

我也看过 throw this,但<catalina_home>/conf/Catalina/localhost/我的 Tomcat 目录中没有目录。

回答by Stefan

Have you tried changing the context path by setting it in the configuration section of the Maven plugin?

您是否尝试通过在 Maven 插件的配置部分中设置来更改上下文路径?

FYI: Find the current version of the plugin here

仅供参考:在此处查找插件的当前版本

  <plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.2</version>

    <configuration>
      <path>/</path>
    </configuration>

  </plugin>

回答by Mav55

I am using tomee and it works for me.

我正在使用 tomee,它对我有用。

Add the context tag to the pom file as follows:-

将上下文标签添加到 pom 文件中,如下所示:-

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.2</version>
 <configuration>
   ..
   <context>ROOT<context>
   ..
 </configuration>
</plugin>