38

I've inherited an app that uses Spring. The original developers are not available. The Spring jar file is just "spring.jar", so there's no version# in the filename to help me. I'd like to download the Spring source corresponding to the jar file. The MANIFEST.MF file has "Spring-Version: 1.2" however that's not precise enough. I've looked at version 1.2.1 and 1.2.9 and it doesn't match up quite right. The key thing is that org.springframework.web.servlet.view.AbstractCachingViewResolver has a prepareView method which is called from resolveViewName and it does not seem to be in 1.2.1 or 1.2.9.

Is there any easy way to track down the right version?

Gary Kephart
  • 4,860
  • 5
  • 39
  • 52

9 Answers9

79

This will do it:

import org.springframework.core.SpringVersion;

public class VersionChecker
{
    public static void main(String [] args)
    {
        System.out.println("version: " + SpringVersion.getVersion());
    }
}

Compile and run this with spring.jar in your CLASSPATH and it'll display the version for you. See the javadocs as well.

user672009
  • 4,379
  • 8
  • 44
  • 77
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I tested this against Spring JARs I have on my desktop. It was able to distinguish between 2.5.2, 2.5.6, and 3.0.0.M2, so I say the code is correct. Besides, it's a class from Spring - are you gonna doubt them? Looks like you have 1.2. – duffymo Jun 03 '09 at 22:57
  • Just checked it against another spring.jar that's some earlier work. I had no idea of the version, but the code came back with 1.2.6. I'm not sure why you only get 1.2. – duffymo Jun 03 '09 at 23:01
  • Except that there's no download for just "1.2". There's 1.2.0, 1.2.0.RC1 and 1.2.0.RC2. I took the time to download all of them, and it looks like I have either RC1 or RC2, both of which have the `prepareView` method. Just 1.2.0 does not have it though. – Gary Kephart Jun 03 '09 at 23:14
  • Yeah, that 3.0.0.M2 JAR that I had included even that last bit. I'm surprised that it didn't show up for you. – duffymo Jun 03 '09 at 23:22
  • But, thanks for getting me close with the SpringVersion.getVersion method. – Gary Kephart Jun 03 '09 at 23:23
  • Thank you - I didn't know it was there until I looked for it. I learned something, too. – duffymo Jun 03 '09 at 23:25
  • 3
    Perhaps someone compiled the JAR themselves from source? – matt b Jun 04 '09 at 01:36
  • But if that source included the SpringVersion class from Rod Johnson's guys, I'd imagine that it would still report the version number faithfully. It's odd that it does not act like the 1.x, 2.x, and 3.x examples that I have. – duffymo Jun 04 '09 at 01:52
  • 1
    getVersion() should be accessed in a static way: SpringVersion.getVersion() – yglodt Dec 20 '12 at 09:56
  • That wasn't true when I wrote this 3.5 years ago. – duffymo Dec 20 '12 at 10:02
  • To me, output was "version: 4.3.0.RELEASE" – Park JongBum Jan 25 '19 at 01:12
  • Sound right. That's an older version - current production version is 5.x. – duffymo Jan 25 '19 at 01:23
16

If your project uses Maven, you can run the following at the command line to see it:

$ mvn dependency:tree | grep org.springframework | grep 'spring-core:jar'
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
  • 2
    This answer was helpful than others, since I couldn't compile the project that wanted to check its spring version. (I wanted to check spring version to create hibernate config :-) and to omit the compile errors) – kavinda Jan 18 '21 at 16:28
9

You cann check it in pom.xml file in <org.springframework-version> tag.

misterGrosar
  • 294
  • 1
  • 3
  • 10
8

The really easy way is to get the MD5 sum of the archive and google it. Many sites that store .jar archives also index the MD5 sums which Google then finds easily. This works really well for pretty much any Java components.

$ md5sum spring-2.5.5.jar
82a2134b227f717066da4f4b059925d3

http://www.google.com/search?q=82a2134b227f717066da4f4b059925d3

vehnae
  • 666
  • 8
  • 5
4

How about checksumming the JAR file and comparing it to the spring.jar files in the distributions from SpringSource? Might take an hour or so to do the downloads, but it should be definitive.

2

According to mvnrepository.com 1.2.9 weights 2.2MB and 1.2.1 weights 2.0MB, that page also has a link for downloading both. I think the weight difference is enough for comparing the files. If you can't see the difference just checksum. If you can't see a relation neither with 1.2.1 nor 1.2.9 you can use the page to download any other version quickly (I use it often)

NOTE: If your JAR is below 2.0MB then I'm afraid duffymo has reason and your JAR is 1.2

victor hugo
  • 35,514
  • 12
  • 68
  • 79
  • 1
    I don't see how size is relevant for determining version. The 1.2.6 version I have is 1.8MB, but they don't choose the version number based on size. Did I miss something about your suggestion? – duffymo Jun 03 '09 at 23:10
2

You can try looking inside the jar's MANIFEST.MF in the META-INF directory - it should indicate what version yo're working with.

Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
0

open the jar & check in spring.jar > META-INF > MANIFEST.MF

enter image description here

JR Sahoo.'JS'
  • 1,338
  • 2
  • 10
  • 11
-1

go to MATA-INF directory and open manifest file.It will be there what version you are using.