maven

maven 环境搭建及打包

一、思维导图

在这里插入图片描述

二、一些重要的配置代码

关于一些依赖项和插件,可以直接去maven官网,看版本下载人数最多的那个。
在这里插入图片描述

推荐一个很好用的软件(UTools)
下载对应的maven文档,然后【Alt+空格】输入“mvn”回车再输入你要的依赖就可以了。

真的很好用!!!!!!呜呜,识别了半个暑假的卡车,火车,飞机……每天和mvn官网说我真的是人类啊,喂!!!
在这里插入图片描述

POM.xml文件(配置java文件)

1.创建时选择

在这里插入图片描述

2.这里需要手动修改1.8

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

3.版本需要修改到4.12

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

4.删除和插件有关的东西

 <finalName>maven03</finalName>
<!--    删除和插件有关的东西-->
<!--    <pluginManagement>&lt;!&ndash; lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) &ndash;&gt;-->
<!--      <plugins>-->
<!--        <plugin>-->
<!--          <artifactId>maven-clean-plugin</artifactId>-->
<!--          <version>3.1.0</version>-->
<!--        </plugin>-->
<!--        &lt;!&ndash; see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging &ndash;&gt;-->
<!--        <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>-->

POM.xml文件(配置war)

1.创建时选择

在这里插入图片描述

2.之后的操作和上面的2.3.4一样

3.添加插件

<!--    准备插件集合-->
    <plugins>
<!--      jetty插件-->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
          <!--        热部署,每10秒扫描一次-->
          <scanIntervalSeconds>10</scanIntervalSeconds>
<!--          当前项目的站点名-->
          <contextPath>/maven03</contextPath>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<!--              启动的端口-->
              <port>9090</port>
            </connector>
          </connectors>
        </configuration>
      </plugin>

<!--      Tomcat插件-->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <!-- 通过maven tomcat8:run运行项目时,访问项目的端口号 -->
          <port>8081</port>
          <!-- 项目访问路径  本例:localhost:9090,  如果配置的aa, 则访问路径为localhost:9090/aa-->
          <path>/maven03</path>
          <uriEncoding>UTF-8</uriEncoding>
          <server>tomcat7</server>
        </configuration>
      </plugin>
    </plugins>

4.maven_controller还要注入服务依赖

  <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

三、打包操作

1.添加Profile配置

<profiles>
    <profile>
      <id>dev</id>
      <properties>
        <env>dev</env>
      </properties>
<!--      未指定环境时通常打包dev(本地测试环境)-->
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
    </profile>
    <profile>
      <id>test</id>
      <properties>
        <env>test</env>
      </properties>
    </profile>
    <profile>
      <id>product</id>
      <properties>
        <env>product</env>
      </properties>
    </profile>
  </profiles>

2.设置资源文件配置

 <build>
    <finalName>maven_package</finalName>
    <resources>
      <resource>
        <directory>src/main/resources/${env}</directory>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
          <include>**/*.tld</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>

3.执行打包操作

clean compile package -Ptest -Dmaven.test.skip=true

在这里插入图片描述

四、附录idea配置maven环境

1.在maven官网下载

官网地址
在这里插入图片描述

2.在idea中配置

maven home directory设置
在这里插入图片描述
User setting file设置
在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值