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

ぐ巨炮叔叔 提交于 2019-12-20 17:37:41

问题


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>

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

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.

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.

I tried both methods from the first answer of 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.

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


回答1:


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

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>



回答2:


I am using tomee and it works for me.

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

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


来源:https://stackoverflow.com/questions/26861999/how-to-set-context-path-to-root-in-tomcat-7-0-when-using-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!