views:

143

answers:

2

According to java ee 5 api ExpressionFactory provides a method #newInstance. I'm using the official javaee-api available in maven: Java EE 5 APIs now in a Maven repository...

But this jar does not provide this method. So I get compiler errors.

How can I get a compilable version without using javaee implementations like e.g. glassfish, openejb?

The official JEE 6.0 jar provided by maven (java.dev.net) contains this method.

+1  A: 

Why don't you want to use the libs from a JEE server ? You'll eventually have to test in one, even if locally. You could use Tomcat, it's easy to install and to use.

In Tomcat for example, all the jars providing the JEE api are available in the lib folder. If you compile using those libs, and stick to the standard JEE API, your code will be compatible with all servers that implement the JEE API.

If you use Maven and don't want to have these libs in your arborescence, and have a server installed, you can use the system dependency type (see here for more informations)

Valentin Rocher
I want to compile for "all" servers, not for one special. And I want to ensure, that I do not use a specific function or class, that is only available in glassfish, but not in jboss for example.
marabol
every java server provides the standard api. if you stick to the class described in the java api, your app will be ok for all servers. I'll complete my answer.
Valentin Rocher
It's not beautiful, but there is no other option, I think...
marabol
why is it not beautiful ? the maven jar you were talking about is just interfaces to provide the basis API, it's not really "prettier"
Valentin Rocher
Actually, this is **not** true, the `newInstance` methods are not in Java EE 5 (and Tomcat is not a reference implementation anymore so running on Tomcat doesn't guarantee anything).
Pascal Thivent
+1  A: 

According to java ee 5 api ExpressionFactory provides a method #newInstance.

Well, javadoc is not a proof and, actually, this is very likely an error in the Java EE 5 javadoc. The two newInstance() factory methods have been added in the Maintenance Review 1 of the JSR-245 (to make EL standalone and take it out of JSP 2.1, have a look at the JSR-245 MR1 Change Log for the details) but that review has never been released.

So it's not surprising that you don't find this method in the java-ee bundle available in the java.net repo.

But this jar does not provide this method. So I get compiler errors.

As expected. This method is not in Java EE 5 (at least this is my understanding). So you need to use:

ExpressionFactory factory = new ExpressionFactoryImpl();

The official JEE 6.0 jar provided by maven (java.dev.net) contains this method.

Yes, because this is Java EE 6, because EL is now standalone, with its own specification (technically, EL is still in JSR-245, sorry if this is confusing). So Java EE 6 includes EL 2.2 (yes, the version jumped from 1.1 to 2.1.2 and then 2.2 for a better alignment with the JSP version). And this version does expose the newInstance() methods on ExpressionFactory.

Pascal Thivent