Idea 配置maven项目中 pom.xml中那些坑

Maven配置与依赖管理
本文介绍了Maven项目配置过程中的常见问题及解决方案,包括如何加快构建速度、正确配置依赖仓库以及在pom.xml文件中如何引用属性。通过具体实例展示了如何避免配置陷阱。

   坑1: 配置maven项目,build速度过慢/卡住/错误,如下图设置属性  archetypeCatalog = internal.
 

坑2 :maven jar包仓库可以来这里:http://mvnrepository.com/。注意在pom.xml中配置depency的时候,如果要使用

<version>${spring.version}</version>,

一定要在最上面properties中引用,如下图

    <profiles>
        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <spring.version>4.3.14.RELEASE</spring.version>
                <hibernate.version>4.3.5.Final</hibernate.version>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>

Over

配置 Mavenpom.xml 文件前,我们需要确保已经安装了 Maven,并且在系统环境变量中配置Maven 的 bin 目录路径,这样才能在命令行中输入 mvn 命令。 接下来的步骤如下: 1.项目根目录下新建一个 pom.xml 文件。 2.pom.xml 文件中添加项目的基本信息,例如项目的 groupId、artifactId、version 等。 3. 配置项目的依赖信息,包括依赖库的 groupId、artifactId、version 等。 4. 配置插件,例如编译插件、打包插件等。 5. 执行 mvn clean install 命令,将项目打包并安装到本地 Maven 仓库中。 下面是一个 pom.xml 文件的示例: ```xml <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> <!-- 项目的基本信息 --> <groupId>com.example</groupId> <artifactId>my-project</artifactId> <version>1.0.0</version> <name>My Project</name> <!-- 项目的依赖信息 --> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>30.0-jre</version> </dependency> </dependencies> <!-- 配置插件 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> </plugins> </build> </project> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值