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

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
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author 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??
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

gudii9Author 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
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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"
0
gudii9Author Commented:
sure let me double check there
0
gudii9Author 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
0
gudii9Author Commented:
here is the attachment again
mavenjars.png
0
gudii9Author 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
0
gudii9Author 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
0
gudii9Author 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?
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Dependencies can include other dependencies. So either spring-core or spring-context (or both) include spring-beans. They call these "transitive dependencies"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.