Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to identify the java version in which the code is written?

Let's say a banking application was developed in Java EE. And we are the new people working on that application now, not sure about the version of the Java EE used to develop that application.

How can we identify the version of Core Java/Java EE in which that project was developed?

like image 265
lea Avatar asked Oct 14 '18 11:10

lea


3 Answers

How can we identify the version of Core Java/Java EE in which that project was developed?

(Note that "developed for" and "runs on" are different questions. I am answering the former ... which is what was asked.)

There is no 100% reliable way to do it.

  • If the project is built using Maven or Gradle, the project's declared dependencies (in the build files) will list specific versions of the Java EE APIs, and (typically) specific Java source and target version.

  • There probably be similar clues in an Ant build file, though in the case of dependencies you will be relying on clues in the pathnames of classpath entries ... which may not be there.

  • For Java EE, there may be clues in the namespace URLs used the XML files; e.g. web.xml, application.xml.

  • If the previous don't help, then you could test compile the codebase with various JDKs and against various Java EE APIs. That should narrow down the range of versions that the codebase is compatible with.

  • If you have existing .class files, then javap can tell you the target bytecode version that was used when building; see this answer. However, this is not a reliable indicator, because it doesn't tell you what version of Java the codebase was developed for.


If you want to find out which version or versions of Java a project is actually compatible with or actually runs on, the only way to find out for sure is to test it.

like image 94
Stephen C Avatar answered Nov 12 '22 18:11

Stephen C


If you want to know which version of Java was used to compile the class, you can use javap, available in the JRE and JDK. It reads your class bytecode and tells you the version.

javap -v out/com/kineolyan/tzio/diffs/Main.class gives you:

Classfile /mnt/Grishka/Projets/project-tz-io/out/com/kineolyan/tzio/diffs/Main.class
  Last modified 9 oct. 2018; size 1806 bytes
  MD5 checksum 26b264396d74f1a68032bf5cd17aab09
final class com.kineolyan.tzio.diffs.Main
  minor version: 0
  major version: 53
  flags: (0x0030) ACC_FINAL, ACC_SUPER
  ....

See this page to match major and minor versions to standard names. For example, 53.0 is Java9.

like image 37
Kineolyan Avatar answered Nov 12 '22 18:11

Kineolyan


To check the java version of a project (if build using maven)

  1. go to pom.xml
  2. check properties
  3. java.version

the code look like this

<properties>
    <java.version>11</java.version>
    <start-class>org.la.ecom.portal.teacher.EcommercePortalTeacherApplication</start-class>
</properties>
like image 23
Mohammad Atif Aftab Avatar answered Nov 12 '22 18:11

Mohammad Atif Aftab