Is there programmatic way to determine which version of the java ee environment is available?
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:
javax.ejb.Singleton
javax.ejb.Stateless
javax.ejb.TimerService
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With