Avatar of gudii9
gudii9
Flag for United States of America asked on

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

Avatar of undefined
Last Comment
mccarl

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mccarl

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gudii9

ASKER
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??
mccarl

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

ASKER
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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
mccarl

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

ASKER
sure let me double check there
gudii9

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gudii9

ASKER
here is the attachment again
mavenjars.png
gudii9

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

ASKER
<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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
gudii9

ASKER
<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?
mccarl

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