Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to determine the Java EE version at runtime?

Is there programmatic way to determine which version of the java ee environment is available?

like image 555
Josue Avatar asked Jan 20 '13 00:01

Josue


2 Answers

There's no standard way to do that. The closest you could do is use reflection/ClassLoader and check for specific API classes/methods that were introduced in a given Java EE version.

Off the top of my head:

  • Java EE 6 / EJB 3.1 added javax.ejb.Singleton
  • Java EE 5 / EJB 3.0 added javax.ejb.Stateless
  • J2EE 1.4 / EJB 2.1 added javax.ejb.TimerService
  • J2EE 1.3 / EJB 2.0 added javax.ejb.MessageDrivenBean

Before that it's J2EE 1.2 / EJB 1.1

Though, note, if this is for Tomcat (judging by the tag), the best way is to just check System.getProperty("tomcat.version"). You should be able to imply the servlet version based on the Tomcat version.

like image 161
David Blevins Avatar answered Oct 08 '22 02:10

David Blevins


I don't know if there is a way to get the Java EE version number, but you can get hold of the Servlet API version number and the JSP version number:

  • You can get the servlet api version in an implementation independent way from a ServletContext object. Look for the getMajorVersion() and getMinorVersion() methods.

  • You can get the JSP version as follows:

    JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion()

And there are no doubt platform (i.e. appserver) specific ways to find or infer various version numbers.


It is worth noting that "Java EE version" is a rubbery concept if you take into account what appserver vendors might do; e.g. cherry-picking the Java EE technologies that they support, and possibly cherry-picking versions. For instance Tomcat does not support all of Java EE - EJB support is missing.

like image 31
Stephen C Avatar answered Oct 08 '22 04:10

Stephen C