Solving "loader constraints violated when linking [...] class" error in Java - java

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?

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).

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.

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.)

Related

Spring Batch Admin - Override configurations are not recognized

I have downloaded the spring-batch-admin 1.3.0.RELEASE project, and updated all of the library references to the most recent RELEASE versions so that they are compatible with my spring-batch environment (eg. spring-xxx 4.1.4.RELEASE).
I have applied the environment settings and overrides per http://docs.spring.io/spring-batch-admin/getting-started.html . However, those overrides are not being recognized.
At least one email chain linked this symptom to the jira issues linked to https://jira.spring.io/browse/SPR-12111 , but those are allegedly fixed in spring core 4.1 .
Since the problem appears to be that the XML files in the project are not being scanned at all (only the ones embedded in the jar files), it seems to me that here should be some obvious way to work around this, even if it is not technically a "fix".
I am open for suggestions.
I resolved this by downloading the latest 1.3.1.RELEASE source from github and building it without any modifications.

javax.el.PropertyNotFoundException: Property 'toArray' not found on type org.hibernate.collection.internal.PersistentSet

I am using hashset.toArray()[x] to display a element in the jsf view, and this is working fine in my machine.
But when I move this on to test server, the above error is thrown.
Both machines are running tomcat 7.
what is causing this error?
The ability to invoke arbitrary non-property-related methods in EL is introduced in EL version 2.2 which goes hand in hand with Servlet 3.0. This feature didn't exist in older versions like Servlet 2.5 / EL 2.1.
So, if you deploy your webapp to a Servlet 3.0 compatible container with a Servlet 3.0 compatible web.xml root declaration, then it will work fine. However, if you deploy your webapp to a container of an older version, or with a web.xml which dictates an older version, or have dropped arbitrary container-specific JAR files of an older version inside webapp's /WEB-INF/lib or even server's own /lib, then this feature won't work.
Provided that you're absolutely positive that the test server is running Tomcat 7 and thus not Tomcat 6 or so, then that can only mean that the web.xml was been changed to dictate an older version, or that your webapp or server's /lib is littered with arbitrary container-specific JAR files such as jsp-api.jar, el-api.jar, etc which would only conflict with container's own libraries (this is often done by ignorant starters in order to workaround compilation errors they face in their IDE; which should have been solved differently).

JAX-WS 2.2 and JDK6 with maven

I have a web service and I'm using the Endpoint.publish("http://0.0.0.0:8080")
Thing is that JAX-WS 2.0 and 2.1 is affected by an issue that throw a NullPointerException when executing endpoint.stop().
The issue is fixed in 2.2 but when adding the dependency in the pom.xml publishing fails due to a java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String; since I'm using java 1.6.
The workaround is to add to the endorsed folder some libs. But I want to pack it all in jar-with-dependencies. An executable java jar.
Said this, I would be thankful if you help me:
Publishing the endpoint in 2.0 or 2.1 listening to all addresses (0.0.0.0)
or
Configuring dependencies in maven to pack everything using 2.2.x
but executable with JDK6
EDIT:
Requirements are a deliverable jar. A single jar that pack all of the dependencies (2 so far, about a 400k jar).
But if you think that the only way to make it work is to add an external shell script please let me know too.
Thank you!
The executable jar format does not allow for endorsed folders required for JAX-WS replacement (and neither does the Java WebStart launcher apparently).
You need to use something that can construct and execute a new "java" command on the fly. The best way from here is most likely to look for an installer which can run the program directly without needing to install.
What exactly do you need to happen?
EDIT: As the requirement is a runnable jar you simply cannot do this with JAX-WS 2.2 Find a workaround with the JAX-WS present in the latest release of the Java version you are targetting.
It is very nice that the JAX-WS stack ship with core Java allowign for very small deployments, but a pain that you cannot easily provide your own.
Note that you can provide your own with Java 5 but then you need to bring your own Endpoint implementation.
Do you need to use the JAX-WS RI? You could use CXF instead which is a fine JAX-WS implementation and doesn't suffer the same collision problems as the RI.
Edit: You could try to generate the classes with the RI, but use CXF in the deployment. JAX-WS is a spec after all so it should work...

How to deal with classpath conflict

In my project, I'm using both glassfish-embedded 3.1.1 and the guava lib... The problem is that glassfish comes with the old implementation of guava (ie google-collections)...
This results in NoSuchMethodError at runtime, for example when using Lists.reverse(), or Sets.newIdentityHashSet() which were introduced later in guava.
I don't find any solution to solve this... (the only one is to manually trash the com/google classes directory in the glassfish jar...)
You can overcome this be specifying the below. Read the Delegation section of the Class Loaders chapter.
<class-loader delegate="false" />
Check this SO post for class loading in Java EE apps in general: Java EE class loading standard
Glassfish should never have included com.google classes in their own jar. That was an error.
UPDATE[#sly7_7]: It seems like glassfish does not include guava in their own jar anymore, but it depends on the guava artifact instead. This should resolve the problem.
Thanks to #JagWire for pointing this.
I was able to make the error go away by using the following Glassfish v4 build:
http://grepcode.com/snapshot/maven.java.net/content/groups/promoted/org.glassfish.main.extras/glassfish-embedded-all/4.0.1-b01
Might be worth taking a look.

Problems with deploying JSF project from Netbeans to Tomcat

Googled everything, but can't find solution for my problem.
When i'm trying to deploy my project to Tomcat, i have such errors in Tomcat log:
SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener
I tried to deploy it from fresh Netbeans 6.8 to fresh Tomcat 6.0.26, but the problem is still there.
Servlet-api.jar is in the tomcat/lib folder. Tried to replace it with the newest, but problem is still there.
No compilation errors. Everything is correct.
Problem started suddenly. No code changes, no new jars added.
Help?
UPD: contents of WEB-INF/lib:
hibernate3.jar
hibernate-testing.jar
quartz-1.7.2.jar
quartz-all-1.7.2
servlet-api-2.5-20081211
java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener
The javax.servlet.ServletRequestListener is newly introduced since Servlet 2.4 API. That your environment cannot seem to find it can be caused by two things:
Either the web.xml is declared as Servlet 2.3 or older which forces the server to Servlet 2.3 compliance mode, or the server in question doesn't support Servlet 2.4 at all.
Classpath is really, really messed up. You should never put/change/remove libraries in JRE/lib, JRE/lib/ext or Tomcat/lib without understanding what you're doing. You should never put appserver-specific libraries in Webapp/WEB-INF/lib because that doesn't make any sense.
To fix 1, ensure that your web.xml is declared as at least Servlet 2.4. Preferably the newest which the server can support. Tomcat 6.0 supports Servlet 2.5, so declare web.xml accordingly.
To fix 2, cleanup the classpath of all pollution. Invest some more time to learn more about the phenomeon "classpath". Handle it with care.
Tomcat doesn't ship with JSF libraries, so you have to include those in WEB-INF/lib. From the listing above it is obvious that your are missing those. For JSF2 go here.
Moreover you do not need servlet-api in WEB-INF/lib, it is a provided library.

Categories

Resources