maven not picking latest jar instead picking old jar from .m2

gudii9
gudii9 used Ask the Experts™
on
Hi,

I am trying simple spring examples like hello world


I see maven not picking latest jars like spring core (4.1.6)instead picking old jar(3.0.5) from .m2.

How to tell maven to take latest but not old jar. I wonder why it is taking old jars. Please advise
mavenjars.png
mavenjars2.png
mavenjars3.png
mavenjars4.png
mavenjars5.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Business Systems Analyst / Software Developer
Top Expert 2015
Commented:
In your first screenshot (and I believe that is what you are mostly talking about), Eclipse (not maven) has "suggested" a version that exists in your .m2 directory. It doesn't go out to connect to any servers on the internet to look for the latest version.

If you want the latest version, go and look on something like https://mvnrepository.com/ and then manually enter that version into the Version input field. Once you save the POM and Eclipse goes to build the project, which will trigger downloading that version, if you ever need to add that same dependency again, Eclipse will have both versions listed in the area below.

Author

Commented:
In your first screenshot (and I believe that is what you are mostly talking about)
correct

a version that exists in your .m2 directory. It doesn't go out to connect to any servers on the internet to look for the latest version.

my .2 has only spring-core release 4.1.6 (not spring-core release 3.0.5)

not sure why eclipse suggested a library of older version which is not in my .m2 folder?
please advise
even my pom.xml also i gave dependency for 4.1.6 not 3.0.5??
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Does your project build correctly with the 4.1.6 dependency in the pom file? If so, then I think that something is broken with your Eclipse because it should definitely list the 4.1.6 version as a possibility in the tree listing in the lower part of that window.

Anyway, it is not a big deal. All this is just a convenience to allow you to add dependencies. Just manually enter the version that you want into your pom file and your done.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Does your project build correctly with the 4.1.6 dependency in the pom file? If so, then I think that something is broken with your Eclipse because it should definitely list the 4.1.6 version as a possibility in the tree listing in the lower part of that window
it worked and got successful output.

How do i know if it took 4.1.6 or 3.0.5 jar internally?
eclipise and amven keeping all the things under the hood and hard to debug or see what is going behind the scenes
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
The pom.xml file is THE official source. If it is 4.1.6 in the pom.xml file then that IS the one that it will be using.

To double check, in the main screen that lists all the files/things in your project (Project Explorer), under your project there should be an item called "Maven Dependencies", and then if you look under that, you should find a .jar file with the name "spring-core-4.1.6.RELEASE.jar"

Author

Commented:
sure let me double check there

Author

Commented:
i checked my pom.xml

it is as below


<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>co.edureka.spring</groupId>
  <artifactId>HelloSpring</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  	<dependency>
  		<groupId>co.edureka.spring</groupId>
  		<artifactId>HelloSpring</artifactId>
  		<version>0.0.1-SNAPSHOT</version>
  	</dependency>
  </dependencies>
</project>

Open in new window


i do not have any dependencies for any jars in that pom.xml. I am trying to add those jars like spring-core, spring-context etc bare minimum jars to make my spring application run.
While adding only it shows old jar that is the problem

Author

Commented:
here is the attachment again
mavenjars.png

Author

Commented:
To double check, in the main screen that lists all the files/things in your project (Project Explorer), under your project there should be an item called "Maven Dependencies", and then if you look under that, you should find a .jar file with the name "spring-core-4.1.6.RELEASE.jar"

i checked other working project which has pom.xml as below (this example i downloaded from below link)
https://www.mkyong.com/spring3/spring-3-hello-world-example/

 
<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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mkyong.core</groupId>
      <artifactId>Spring3Example</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>Spring3Example</name>
      <url>http://maven.apache.org</url>

      <properties>
            <spring.version>3.0.5.RELEASE</spring.version>
      </properties>

      <dependencies>
            <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.8.2</version>
                  <scope>test</scope>
            </dependency>

            <!-- Spring 3 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>

      </dependencies>
</project>

MAven dependencies show spring-core-3.0.5-Release.jar
i wonder where that is coming from?
mavenDependencies.png

Author

Commented:
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.mkyong.core</groupId>
	<artifactId>Spring3Example</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>Spring3Example</name>
	<url>http://maven.apache.org</url>

	<properties>
		<spring.version>4.1.6.RELEASE</spring.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.2</version>
			<scope>test</scope>
		</dependency>

		<!-- Spring 3 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>

	</dependencies>
</project>

Open in new window


i changed pom as above to 4.1.6 release and as soon as i save my jars updated to 4.1.6 as attached
mavenDependencies2.png

Author

Commented:
<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			
		</dependency>

Open in new window


i do not have above spring-beans dependency in pom.xml right? but how the Maven Dependecies got spring-beans-4.1.6.jar?
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Dependencies can include other dependencies. So either spring-core or spring-context (or both) include spring-beans. They call these "transitive dependencies"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial