0

I'm working first time with Maven project. Just created new Maven project in eclipse and in pom.xml I've added below configuration. Like Spring, log4j's jar version etc

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

The moment I save my pom.xml file, It automatically creates folder at C:\Users\trisha\.m2 location with respective jars in it, the one I've mentioned in pom.xml.

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

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 ?

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

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

Lenny
  • 63
  • 1
  • 9
  • 5
    There is an awesome 30 minutes introduction to Maven. https://maven.apache.org/guides/getting-started/index.html You should always look at documentation prior to asking here. And remember that official documentation is always the most complete and will answer to each point. – LppEdd Feb 23 '19 at 08:50

1 Answers1

1

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

In pom.xml you mention something like this:

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

It will download the xx version 1.1 library automatically.

  1. Search xx in Maven local repository.
  2. Search xx in Maven central repository.
  3. Search xx in Maven remote repository (if defined in 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 ?

Yes, exactly.

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 ?

yes , see the above 2 answers combined. You can also ad jars manually by building path and then selecting the required jars. Better suggestion is always to use maven. To get the latest Jar there are some parenthesis tweaks which you can find here

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

yes, it is possible.

In your settings.xml change the below lines:<localRepository>C:\Users\me\.m2\repo</localRepository> to point to your desired folder.

Vishwa Ratna
  • 4,468
  • 4
  • 24
  • 46
  • 1
    Generally correct, but Maven will not upgrade dependencies automatically to newer versions. – J Fabian Meier Feb 23 '19 at 09:06
  • You have mentioned to change `m2.conf`which does not make sense. The location where you have the localrepository can be changed within the `settings.xml` if you like. So the part about `m2.conf` is simply wrong and setting `maven.home` does not make sense either. – khmarbaise Feb 23 '19 at 09:10
  • changed the answer, thanks for making it better guys! – Vishwa Ratna Feb 23 '19 at 09:12