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

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

问题描述:

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

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

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

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

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

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

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

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

我想在http://localhost:8080/上运行我的应用程序.

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

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

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

我从.

第一种方法对我不起作用,重命名战争之后,一切都没有改变,tomcat7:run-war-only要求使用名称为projectname-0.0.1-SNAPSHOT.war的战争.

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.

第二种方法什么也没改变(我都尝试过

The second method changed nothing (I tried both

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

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

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

仅供参考:在此处找到

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

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

  </plugin>