程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

# Maven 知识及常见问题

发布于2021-05-30 00:57     阅读(887)     评论(0)     点赞(18)     收藏(0)



Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。

Maven 安装

安装步骤
  • 下载maven配置环境变量,即可使用
settingx.ml常用仓库地址
  • 阿里云仓库

    <mirrors>
        <mirror>         
            <id>alimaven</id>
            <name>aliyun maven</name> 
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
            <mirrorOf>central</mirrorOf> 
        </mirror> 
    </mirrors>
    
Idea 使用maven常见坑
  • Idea右侧Profiles下面的每个maven项目报红,因为项目无法识别到当前的maven项目,右键unlink maven projects,点击加号重新添加项目。
  • 编译的时候如果class文件中已经存在了,但是Idea报找不到类并且报红,可以尝试上面的方法。或者清理Idea的缓存重启。
  • 当仓库中的jar包问题混乱时候,可以重新指定maven的地址,重新拉去jar包。

Maven 常用命令

在这里插入图片描述

mvn clean

运行该命令,会删除项目的target整个目录。

mvn install

将maven项目,编译、打包到本地仓库。
在这里插入图片描述

mvn deploy

将项目进行打包发布到远端仓库中。

mvn compile

编译项目


pom.xml配置

排除依赖中的某个包
  • 当项目中的依赖有冲突的时候,可以排除相关的jar,可以不用排除,但是因为冲突报错的时候需要排除相关jar
<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </exclusion>
    </exclusions>
    <version>3.5.0</version>
</dependency>
配置 maven编译的版本
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
maven 文件资源的配置
<build>
    <!-- 构建最终生成项目的名字 -->
    <finalName>maven-test</finalName>
    <!-- 构建产生的文件存放目录 -->
    <directory>./ldtest</directory>
    <!-- 项目资源的路径 -->
    <resources>
        <resource>
            <!-- 指定资源文件编译后放置的目录,根目录是target/classes -->
            <targetPath>./ldtest/resources</targetPath>
            <directory>${basedir}/src/main/resources</directory>
            <!-- 筛选需要编译的文件 -->
            <includes>
                <include>*.xml</include>
            </includes>
            <!-- 排除之外的文件 -->
            <excludes>
                <exclude>*.properties</exclude>
            </excludes>
        </resource>
    </resources>
</build>

原文链接:https://blog.csdn.net/qq_37248504/article/details/117262604



所属网站分类: 技术文章 > 博客

作者:听说你没有见过我

链接:http://www.javaheidong.com/blog/article/208014/ef6130599aee4698fc0a/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

18 0
收藏该文
已收藏

评论内容:(最多支持255个字符)