Java.lang.NoClassDefFoundError: in an anonymous inner class

I'm running this code on Linux Red Hat using the JVM 1.6_23 sun / oracle inside the VMWare server.

Several times, the JVM does not seem to be able to access my anonymous inner classes.

My class path is wonderful, as it works for a certain period of time.

All I got are errors like this:

java.lang.NoClassDefFoundError : com/mycompany/impl/MyClassImpl$1 with com.mycompany.impl.MyClassImpl.markAsDeletable ( MyClassImpl.java : 45).

line 45 - the first line below, she can not find my new Predicate

  DomaineVO domaineVO = Iterables.find(domainesVO, new Predicate<DomaineVO>() { @Override public boolean apply(DomaineVO input) { return input.getId().equals(domaine.getIdentifier().toString()); } }); 

Any ideas?

+7
source share
3 answers

Finally, I think we could handle the problem.

We run this code on the dock, and we use the automatic deployment of .war files. By default, jetty uses java.io.tmpdir to deploy .war files.

Our problem was only on Linux, and mostly early in the morning (as soon as the first office worker used the application).

The reason was clearing / tmp at night (done by the LOGROTATE command on our servers).

Thumb rules: never use / tmp for too long and create a war to deploy in your own folder.

Thanks everyone

+4
source

It seems that the JVM cannot find the class file for the anonymous class. This would be called "MyClassImpl $ 1.class" - if it is not in the classpath, something should have deleted it. If present, something is wrong with the JVM.

+2
source

It sounds very strange. Firstly, if the code has been running for a while, as you say, the file should be there. Secondly, the JVM rarely unloads a class from memory after using it. Some JVMs will do this in hard memory or as part of the GC, but they usually stick with it as an optimization.

My only assumption: you are using the JVM in a situation where ClassLoaders are changing. If you use Netbeans (especially), but I think it is also an eclipse, then if you partially recompile the code, then the class loaders may not match. Does it work in an IDE?

An alternative is to change the ClassLoader. If you are republishing to a running web server or application server, then the old class will not have the appropriate class loader for the new instance. ClassLoader may not be able to find the old version, even if there is a file. Are you resubmitting to the app / web server?

Finally, I suggest that this is possible with serialization. If the Serializable class and serialVersionUID do not match, I assume this could happen. Do you serialize objects here?

+1
source

All Articles