views:

200

answers:

3

I am new to Java and experiencing problems understanding exceptions thrown by the framework.

Right now, I am trying to implement a regular expression validator into an application consisting of Java 5 EE with myFaces 1.2 and Tobago running in an apache tomcat 5.5.

I followed a couple of tutorials (including the Java 5 EE tut from SUN) and came pretty far. However, when calling my jsp, I get the following error message:

java.lang.LinkageError: loader constraints violated when linking javax/faces/validator/Validator class

Can anyone explain to me what I need to do to solve this problem?

So far, it seems as if MyFaces 1.1.7 has a version conflict to TomCat 5.5. Both contain javax.* packages (one of them namely javax.faces.validator). The validator class has a different version in the packages. The corresponding MyFaces library is called myfaces-api-1.1.7.jar and the TomCat library is called javaee.jar.

The included javax packages in the myfaces lib is a subset of the packages from within the javaee lib. However... I cannot skip any of both, because the project will fail to start then.

Any tipps?

+2  A: 

This is almost certainly caused by your application having its own copy of Validator (in one of its JAR files), and this is clashing with the server's own copy. Something this can cause a LinkageError.

Find out which of your WAR or EAR's JAR files contains that, and remove it (along with the rest of the javax.faces classes).

skaffman
I believe I found the source of the exception, however, I don't know how to solve this problem.Under Libraries in Eclipse, I can see Apache Tomcat v5.5 with the library javaee.jar containing a lot of javax packages including the javax.faces.validator package. Additionally, I can see JSF MyFaces 1.1 with the library myfaces-api-1.1.7.jar containing a couple of javax packages also including the javax.faces.validator package.How do I solve this, as I believe I need both libraries and cannot remove one without breaking my project?
Mephisztoe
If Tomcat has the javax.faces as part of its libraries, then it should also include a full implementation, and your application doesn't need myfaces-api-1.1.7.jar at all
skaffman
Removing myfaces-api-1.1.7.jar immediately results in an UnsupportedOperationException when the webapp is started:java.lang.UnsupportedOperationException / javax.faces.context.FacesContext.getELContext(FacesContext.java:137)
Mephisztoe
hmm, ok looks like the JSF in Tomcat is a different version to the JSF in your application. You might have to repack myfaces-api-1.1.7.jar, removing the jabax classes, but keeping everything else.
skaffman
A: 

Perhaps you've got two conflicting versions of the same library available on your classpath. For example, you might have a jar file in WEB-INF/lib that's already provided in TOMCAT_HOME/lib. (el-api.jar is a common culprit, but there are other possibilities.)

Jonathan Feinberg
+1  A: 

Sounds like a classpath problem. Check your classpath for two jars with conflicting versions (both containing the javax.faces.validator.Validator class)


According to the MyFaces homepage. Tomcat Config: Tomcat 5.5.x

Some users have reported problems when using MyFaces with Tomcat 5.5.x. Here is a short guide that will hopefully help you not run into the same problems :-)

If your are using the binary version of MyFaces: MyFaces is packaged so that it works with Tomcat 5.0.x so the WEB-INF/lib/jsp-2.0.jar and WEB-INF/lib/commons-el.jar JAR files must be removed from your WAR files (including the examples).

If you are building from source: If you want to build MyFaces from scratch to work with Tomcat 5.5.x, you have to set the property tomcat.pre.5.5.version in the $MYFACES_HOME/build/build.default.properties file to the value false.

jitter
As commented in skaffman's reply, I found the jars: javaee.jar and myfaces-api-1.1.7.jar. I only dont know how to solve that conflict as I need both...
Mephisztoe
Check expanded answer maybe this applies to you
jitter
Under WEB-INF/lib I don't have jsp-2.0.jar nor commons-el.jar. However, I have another directory containing libs that are included in my project. The MyFaces directory contains a commons-el.jar file but no jsp-2.0.jar file. The included TomCat libraries contain a jsp-api.jar. However, what I don't understand is, neither commons nor jsp contain any of the javax.faces.validator packages.
Mephisztoe