Tomcat Maven Plugin for embedded Tomcat 8.5

2020-06-21 07:42发布

问题:

I'm running a Spring web application and failing to execute embedded tomcat in latest Eclipse with Tomcat 8.5 using Tomcat 7 Maven Plugin , I'm running tomcat7:run-war goal on windows but failed to configure it to run Tomcat 8.5, it keeps finding tomcat 7 folder.

tomcat7:run-war Runs the current project as a packaged web application using an embedded Tomcat server.

I found answer or this answer but it's good for deploying tomcat .

I found in a deleted link tomcat8 plugin. Is it relevant?

I found issue that suggest use spring boot feature instead, can someone provide more details?

it appears this project is dead, I recommend you look into using Spring Boot which has very similar features: https://spring.io/projects/spring-boot

Especially when Spring Boot 2.1 won't support Tomcat7

回答1:

Yeah, I think that using spring boot configuration is the best option here. To use a specific tomcat version you should do the following steps:

1- Make sure that you have spring boot as the project <parent> in your pom.xml:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
 </parent>

2- Add the tomcat.version to <properties>:

<properties>
    ...
    <tomcat.version>8.5.35</tomcat.version>
    ...
</properties>

And that's it, import the new dependencies and the application should run as an embedded Tomcat with the version that you specify in step 2.

Having said that, be aware that there are some issues with certain tomcat versions. I would suggest you that, if you want to use an 8.5.X version, use the 8.5.35 which I tested and it's working perfectly.

Hope this helps you.