java - maven如何进行Jar下载?

标签 java maven

我是第一次使用 Maven 项目。刚刚在 eclipse 中创建了新的 Maven 项目,并在 pom.xml 中添加了以下配置。比如Spring、log4j的jar版本等

<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.LearnJavaSpring</groupId>
  <artifactId>TalendJavaSpring</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>

    <properties>
        <spring.version>5.1.4.RELEASE</spring.version>
    </properties>
</project>

当我保存 pom.xml 文件时,它会自动在 C:\Users\trisha\.m2 创建文件夹其中包含相应 jar 的位置,即我在 pom.xml 中提到的那个。

1)我的疑问是,maven 从哪里自动在上述文件夹位置获取这些 jar ? maven会自动下载依赖吗?

2) 这样想是否正确,Maven 解析 pom.xml当我们保存该文件并下载 pom.xml 中提到的所有依赖项或 jar 时文件 ?

3) 如果我希望 Maven 从 Maven 所在的不同位置下载 jars,该怎么办? maven 会自动下载最新的 jar 吗?

4) 是否可以更改此默认文件夹位置 C:\Users\trisha\.m2到其他地点?如果是,如何..?

最佳答案

1) My doubt is, From where maven got these jars automatically in above folder location ? Does maven downloads the dependencies automatically ?

在 pom.xml 中你提到了这样的内容:

<groupId>xx</groupId>
<artifactId>yyy</artifactId>
<version>1.1</version>

它将自动下载xx版本1.1库。

  1. 在 Maven 本地存储库中搜索xx
  2. 在 Maven 中央存储库中搜索xx
  3. 在 Maven 远程存储库中搜索xx(如果在 pom.xml 中定义)。

2) Is it correct to think in this way that, Maven parse the pom.xml file when we save that and download all the dependencies or jars mentioned in pom.xml file ?

是的,完全正确。

Reference

3) What if I want maven to download jars from the different location from where Maven does ? Does maven automatically downloads the latest jars ?

是的,请结合以上 2 个答案查看。您还可以通过构建路径然后选择所需的 jar 来手动广告 jar。更好的建议是始终使用 Maven。 要获取最新的 Jar,您可以找到一些括号调整 here

4) Is that possible to change this default folder location C:\Users\trisha.m2 to other location ? If yes, How..?

是的,这是可能的。

在您的 settings.xml 中更改以下行:<localRepository>C:\Users\me\.m2\repo</localRepository>指向您想要的文件夹。

关于java - maven如何进行Jar下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54839772/

相关文章:

java - 此类问题的模式

java - 峰值内存使用不超过限制

java - 搭建游戏!项目与maven

java - 如何在项目中找到不需要的jar

java - 将非常宽(超过 1600 列)的查询导出到 CSV

java - 如何记录多个方法的 javadoc 异常原因

java - 我的第一个 servlet 遇到问题

java.lang.NoClassDefFoundError : org/slf4j/impl/StaticLoggerBinder

java - 如何将普通 Java 项目功能添加到 Eclipse (.ear) 中的 EJB 项目?

java - 无法使用 thymeleaf 运行 Spring Boot 应用程序