亲测有效:Maven3.8.1使用Tomcat8插件启动项目

我本地maven的settings.xml文件中的配置:

XML 复制代码
<mirror>
	<id>aliyunmaven</id>
	<mirrorOf>central</mirrorOf>
	<name>阿里云公共仓库</name>
	<url>https://maven.aliyun.com/repository/public</url>
</mirror>

在pom.xml文件中添加tomcat8插件:

之前试过tomcat7,直接更新pom文件即可使用,这里略过

XML 复制代码
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <release>11</release> <!-- 使用的 JDK 版本 -->
        </configuration>
    </plugin>

    <!--使用tomcat7也可以-->
    <!-- <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.2</version>
     </plugin>-->
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat8-maven-plugin</artifactId>
        <version>3.0-r1655215</version>
        <configuration>
            <url>/maven_web</url>
            <server>tomcat</server>
        </configuration>
    </plugin>
</plugins>

报错如下: 在阿里云仓库中找不到

网上文章说在pom.xml文件中添加如下的配置:但仍旧无效,所以下面的配置不管用!

XML 复制代码
<pluginRepositories>
        <pluginRepository>
            <id>alfresco-public</id>
            <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
        </pluginRepository>
        <pluginRepository>
            <id>alfresco-public-snapshots</id>
            <url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>beardedgeeks-releases</id>
            <url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>
        </pluginRepository>
    </pluginRepositories>

后来找到文章,将下面的镜像放到maven的settings.xml文件中:

XML 复制代码
<mirror>
	<id>alfresco</id>
	<name>alfresco maven</name>
	<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
	<mirrorOf>central</mirrorOf>
</mirror>

但是仍然说无法解析:

重新下载,报错说在阿里云这个仓库中找不到:

没有从我们添加的仓库中找,说明两个有冲突,注释掉阿里云试试:

可以下载了:

需要多等待一会儿,因为tomcat8有很多相关依赖,这是下载好的依赖:

运行tomcat8:run命令:

点击下图中的链接:

访问成功!

注意:以下非常重要!

使用tomcat8插件启动项目时,需要把阿里云注释掉:

当不使用tomca8插件启动项目时,就把阿里云解开注释,把alfresco注释掉:

两个仓库有冲突,推荐在Edit Configurations中使用本地Tomcat,速度更快一些,不需要下载那么多依赖:


参考文章:

  1. Maven中如何使用tomcat8的插件
  2. https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin/3.0-r1655215
  3. Sonatype Nexus Repository
  4. Maven使用tomcat8-maven-plugin插件
  5. [记一记系列]maven使用Tomcat8插件的遇到问题和解决办法
  6. https://github.com/apache/tomcat-maven-plugin/tree/trunk
  7. Maven使用tomcat8-maven-plugin插件
  8. 阿里云云效 Maven

这个问题困扰了我两天,找了很多文章都不行,所以网上的文章也不一定可靠,还需要自己动手慢慢调试,实践出真知呀~~

相关推荐
程序员buddha16 小时前
【Spring】idea + maven 从零创建Spring IoC容器示例
spring·maven·intellij-idea
程序员buddha16 小时前
使用 IDEA + Maven 搭建传统 Spring MVC 项目的详细步骤(非Spring Boot)
spring·maven·intellij-idea
理想奋斗中1 天前
Maven安装配置以及Idea中的配置教程
java·maven
张张张3121 天前
4.29-4.30 Maven+单元测试
java·单元测试·maven
阿常111 天前
解决Maven项目中报错“java不支持版本6即更高的版本 7”
java·开发语言·maven
forestsea2 天前
Maven 实现多模块项目依赖管理
java·maven
weixin_456588153 天前
【Maven】子POM与父POM
java·maven
Alsn863 天前
8.idea创建maven项目(使用Log4j日志记录框架+Log4j 介绍)
log4j·maven·intellij-idea
鸠。3 天前
第四章 Maven
java·数据库·maven
金斗潼关4 天前
使用Nexus搭建远程maven仓库
java·maven·nexus