2

As per this below snapshot, I see list of packages for hibernate:

enter image description here

I regularly see update index activity by m2e plugin(maven) in eclipse, for which I have no clue, What does it mean?

Where are these packages fetched from and displayed?

What is groupId/ArtifactId? Why can't one just say package/class instead?

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • possible duplicate of [What is a Maven artifact?](http://stackoverflow.com/questions/2487485/what-is-a-maven-artifact) –  Jun 02 '15 at 05:29

1 Answers1

3

Where are these packages fetched from and displayed?

By default, Maven will download from the Maven Central Repository, which is located at this URL: http://search.maven.org/

You can also add a custom repository by using the <repository> tag. Here is an example of how you can add the JBoss repository to your Maven project:

<project>
    <repositories>
        <repository>
            <id>JBoss repository</id
            <url>http://repository.jboss.org/nexus/content/groups/public/</url>
        </repository>
    </repositories>
</project>

Maven will download the artifacts when it needs them. So doing an mvn update or mvn install would trigger Maven to go to the repository if it doesn't already have the necessary JARs locally. And the local folder where the JAR files gets stored is C:\Users\your_windows_user\.m2\repository by default.

What is groupId/ArtifactId? Why can't one just say package/class instead?

Maven operates by managing dependencies, which are individual JAR files. So if you need to use a class, Maven will pull in the entire JAR file containing that class. The main reason for this is that Java libraries typically ship as JAR files, not individual classes.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • For your point: "By default, maven will download", Does it start downloading after you create a maven project? Where does it store on windows box after download? – overexchange Jun 02 '15 at 05:37
  • So, "add dependency" tool shown in above screenshot is searching from `.m2\repository` of local box, but not from remote, correct? – overexchange Jun 02 '15 at 05:49
  • 1
    The add dependency actually gets its list of dependencies from the Central Repository. I would assume that if you select a dependency and you already have the JAR file locally, then it will not download it again. – Tim Biegeleisen Jun 02 '15 at 06:02
  • As you said: "Maven will download the artifacts when it needs them.", But I see that `.m2\repository` already has `org.hibernate` package before I need it. My proect was just a single jsp. When I actually required hibernate-core, I had to delete existing folder and run add-dependency tool.How do I understand this? – overexchange Jun 02 '15 at 09:21
  • Once the `hibernate-core` JAR is in your `.m2` folder, Maven will not download again unless you force it to do an update. – Tim Biegeleisen Jun 02 '15 at 09:40
  • One supplementary, How do I decide, what are the dependency jars that are required to execute my "spring nature" project? author has just dumped the dependency [here](https://code.google.com/p/jee-tutorial-youtube/source/browse/trunk/j2eeapplication/pom.xml) without explaining which dependency is required for what? I agree with the author to avoid this explanation, but how do I learn the required dependencies? Here is the [video](https://www.youtube.com/watch?v=PM-f8ROIhTU&list=PLHqN89yRGMyAcwWcSWk59_S_-BQVn3Rrb&index=9) where he dumps it at time 20:50 – overexchange Jun 02 '15 at 10:31
  • Maven version 2.0 and higher has a feature called transitive dependency management. This means that Maven will automatically scan the POM file of any dependencies you include to see and download any dependencies on which it relies. So in your example if you include Spring stuff in your POM, Maven will do its magic and figure out what JARs it needs in your `.m2` folder automatically. – Tim Biegeleisen Jun 02 '15 at 10:53
  • These are all great questions. Read [here](http://www.tutorialspoint.com/maven/maven_manage_dependencies.htm) for more information on transitive dependencies. – Tim Biegeleisen Jun 02 '15 at 10:53