IDEA使用Maven

创建MavenWeb项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

观察maven-repo仓库多了什么?

在这里插入图片描述

IDEA中Maven设置

在这里插入图片描述

在IDEA标记文档的文件属性

在main目录下,创建两个文件夹

源码目录 java
资源目录 resources

将文件夹进行标记属性

java 标记为 源码目录
resources 标记为 资源目录
在这里插入图片描述

pom文件——重要文件

在这里插入图片描述
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!--这里就是我们刚配置的GAV-->
  <groupId>com.kuang</groupId>
  <artifactId>javaweb-01-maven</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--项目的打包方式-->
  <packaging>war</packaging>

  <name>javaweb-01-maven Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>
  <!--配置-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!--编号版本-->
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  <!--项目依赖-->
  <dependencies>
    <!--具体依赖jar包的位置-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <!--<dependency>-->
      <!--<groupId>org.springframework</groupId>-->
      <!--<artifactId>spring-webmvc</artifactId>-->
      <!--<version>5.3.5</version>-->
    <!--</dependency>-->
  </dependencies>

  <!--项目构建用的东西-->
  <build>
    <finalName>javaweb-01-maven</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

依赖一些常用的jar包

maven仓库——https://mvnrepository.com/

<dependencies>
  <!--具体依赖jar包的位置-->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
  </dependency>
   <!--spring mvc的jar包-->
  <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.5</version>
  </dependency>
</dependencies>

Maven导出的问题

问题:由于Maven的约定大于配置,我们以后可能遇到我们写的配置文件,无法被导出或者生效的问题,
解决方案:在Build下加一个 resources 属性

<!--在build中配置resources,来防止我们的资源导出失败的问题-->
<build>
      <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.xml</exclude>
             </excludes>
            <filtering>false</filtering>
        </resource>
        <!--原因:java下只能写java文件,我们写的xml文件可能导出失败-->
        <!--方案:includes加入一些配置-->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

IDEA的操作

在这里插入图片描述
在这里插入图片描述

解决遇到的问题

第一个问题:Maven版本问题

在这里插入图片描述降低Maven的版本 3.6.1可以:官网下载以前版本
https://archive.apache.org/dist/maven/maven-3/
找需要下载的版本,在选择binaries目录,下载bin.zip的文件
在这里插入图片描述
在这里插入图片描述

问题二:同名的问题

在这里插入图片描述解决方案:查看项目目录下是否已删除干净

问题三:Tomcat闪退

解决方案:jdk的环境变量没有配好,Tomcat的运行需要jdk的支持,重新配置JAVA_HOME环 境变量

问题四:Maven默认web项目中的web.xml版本问题——太老

解决方案:参考自己的Tomcat中的web.xml版本,找到webapps下的web.xml文件,查看当前的版本进行更改

下一篇:使用Maven仓库与Servlet的使用

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值