NoClassDefFoundError

The public knowledge pool and discussion forum of the OWS community. Do not post confidential information here!
sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

NoClassDefFoundError

Post by sg431 »

A NoClassDefFoundError occurs in our applications. It happens only when starting via Openwebstart (not every time). With Oracle-Webstart and locally in Eclipse the error does not occur. Here is an example with the geotools library:

Code: Select all

Caused by: java.lang.NoClassDefFoundError     at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)     at 
java.lang.reflect.Constructor.newInstance(Unknown Source)     at 
java.util.concurrent.ForkJoinTask.getThrowableException(Unknown Source)    at 
java.util.concurrent.ForkJoinTask.reportException(Unknown Source)     at 
java.util.concurrent.ForkJoinTask.invoke(Unknown Source)     at 
java.util.stream.ForEachOps$ForEachOp.evaluateParallel(Unknown Source)     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(Unknown Source)     at
java.util.stream.AbstractPipeline.evaluate(Unknown Source)     at 
java.util.stream.ReferencePipeline.forEach(Unknown Source)     at 
java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)     
at  ... 
18 more 
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.geotools.referencing.cs.DefaultCoordinateSystemAxis     at 
org.geotools.referencing.factory.TransformedAuthorityFactory.<clinit>(TransformedAuthorityFactory.java:105)     at 
org.geotools.referencing.factory.epsg.DirectEpsgFactory.<init>(DirectEpsgFactory.java:525)     at 
org.geotools.referencing.factory.epsg.FactoryUsingSQL.<init>(FactoryUsingSQL.java:51)     at 
org.geotools.referencing.factory.epsg.FactoryUsingAnsiSQL.<init>(FactoryUsingAnsiSQL.java:119)     at 
org.geotools.referencing.factory.epsg.hsql.FactoryUsingHSQL.<init>(FactoryUsingHSQL.java:51)     at 
org.geotools.referencing.factory.epsg.hsql.ThreadedHsqlEpsgFactory$1.<init>(ThreadedHsqlEpsgFactory.java:320)     at 
org.geotools.referencing.factory.epsg.hsql.ThreadedHsqlEpsgFactory.createBackingStore(ThreadedHsqlEpsgFactory.java:320)     at 
org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore0(ThreadedEpsgFactory.java:393)     at 
org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:434)     at 
org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:114)     at 
org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:245)     at 
org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:100)     at 
org.geotools.util.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:761)     at 
org.geotools.util.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:584)     at 
org.geotools.util.factory.FactoryRegistry.lambda$getFactories$0(FactoryRegistry.java:267)     at 
java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)     at 
java.util.Spliterators$IteratorSpliterator.tryAdvance(Unknown Source)     at 
java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(Unknown Source)     at 
java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(Unknown Source)     at 
java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(Unknown Source)     at 
java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(Unknown Source)     at 
java.util.Spliterators$1Adapter.hasNext(Unknown Source)
at org.geotools.util.LazySet.isEmpty(LazySet.java:98)     at 
org.geotools.referencing.factory.ManyAuthoritiesFactory.<init>
(ManyAuthoritiesFactory.java:131)     at 
org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:110)     at 
org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:63)     at 
org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:240)     at 
org.geotools.referencing.CRS.decode(CRS.java:518)     at 
org.geotools.referencing.CRS.decode(CRS.java:434)     at 
org.geotools.data.wfs.internal.v2_0.FeatureTypeInfoImpl.getCRS(FeatureTypeInfoImpl.java:140)     at
...
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)     at 
java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)     at java.util.stream.AbstractPipeline.copyInto(Unknown Source)     at 
java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source) at 
java.util.concurrent.CountedCompleter.exec(Unknown Source)     at 
java.util.concurrent.ForkJoinTask.doExec(Unknown Source)     at 
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)     at 
java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)     at 
java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) 
WARN (FactoryRegistry.java:1114) - Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: 
org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated". java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated     at 
java.util.ServiceLoader.fail(Unknown Source)     at 
java.util.ServiceLoader.access$100(Unknown Source)     at 
java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)     at 
java.util.ServiceLoader$LazyIterator.next(Unknown Source)     at 
java.util.ServiceLoader$1.next(Unknown Source)     at 
org.geotools.util.factory.FactoryRegistry.register(FactoryRegistry.java:967)     at 
org.geotools.util.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:873)     at 
org.geotools.util.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:903)     at 
org.geotools.util.factory.FactoryRegistry.getFactories(FactoryRegistry.java:265)     at 
org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:183)     at 
org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:453)     at 
org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:83)     at 
org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:63)     at 
org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:240)     at 
org.geotools.referencing.CRS.decode(CRS.java:518)     at 
org.geotools.referencing.CRS.decode(CRS.java:434)     at 
org.geotools.data.wfs.internal.v2_0.FeatureTypeInfoImpl.getCRS(FeatureTypeInfoImpl.java:140)     at
 ...
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)     at 
java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)     at 
java.util.stream.AbstractPipeline.copyInto(Unknown Source)     at 
java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source) at
java.util.concurrent.CountedCompleter.exec(Unknown Source)     at 
java.util.concurrent.ForkJoinTask.doExec(Unknown Source)     at 
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)     at 
java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)     at 
java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) 
Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
org.geotools.referencing.factory.epsg.CartesianAuthorityFactory     at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)     at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)     at
 java.lang.reflect.Constructor.newInstance(Unknown Source)     at 
java.lang.Class.newInstance(Unknown Source)     ... 33 more 


WARN (FactoryRegistry.java:1114) - Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated". java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated     at 
java.util.ServiceLoader.fail(Unknown Source)     at 
java.util.ServiceLoader.access$100(Unknown Source)     at 
java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)     at 
java.util.ServiceLoader$LazyIterator.next(Unknown Source)     at 
java.util.ServiceLoader$1.next(Unknown Source)     at 
org.geotools.util.factory.FactoryRegistry.register(FactoryRegistry.java:967)     at 
org.geotools.util.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:873)     at 
org.geotools.util.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:903)     at 
org.geotools.util.factory.FactoryRegistry.getFactories(FactoryRegistry.java:265)     at 
org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:183)     at 
org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:453)     at 
org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:83)     at 
org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:63)     at 
org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:240)     at 
org.geotools.referencing.CRS.decode(CRS.java:518)     at 
org.geotools.referencing.CRS.decode(CRS.java:434)     at 
org.geotools.data.wfs.internal.v2_0.FeatureTypeInfoImpl.getCRS(FeatureTypeInfoImpl.java:140)     at 
...
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)     at
java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)     at 
java.util.stream.AbstractPipeline.copyInto(Unknown Source)     at 
java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source)     at 
java.util.concurrent.CountedCompleter.exec(Unknown Source)     at 
java.util.concurrent.ForkJoinTask.doExec(Unknown Source)     at 
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)     at 
java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)     at 
java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) 
Caused by: java.lang.ExceptionInInitializerError     at 
si.uom.NonSI.<clinit>(NonSI.java:128)     at 
org.geotools.referencing.cs.DefaultCoordinateSystemAxis.<clinit>(DefaultCoordinateSystemAxis.java:107)     at 
org.geotools.referencing.cs.AbstractCS.<clinit>(AbstractCS.java:79)     at 
org.geotools.referencing.crs.DefaultEngineeringCRS.<clinit>(DefaultEngineeringCRS.java:78)     at 
org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.<clinit>(CartesianAuthorityFactory.java:54)     at
 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at 
 sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)     at 
 java.lang.reflect.Constructor.newInstance(Unknown Source)     at java.lang.Class.newInstance(Unknown Source)   
   ... 
 33 more Caused by: java.lang.IllegalArgumentException: NumberSystem tech.units.indriya.function.DefaultNumberSystem not found     at 
 tech.units.indriya.function.Calculus.getNumberSystem(Calculus.java:118)     at 
 tech.units.indriya.function.Calculus.currentNumberSystem(Calculus.java:90)     at 
 tech.units.indriya.AbstractUnit.divide(AbstractUnit.java:477)     at 
 tech.units.indriya.AbstractUnit.divide(AbstractUnit.java:368)     at 
 tech.units.indriya.unit.Units.<clinit>(Units.java:231)    
  ... 43 more
So it seems to have to do with how Openwebstart loads the classes. The necessary libraries are present in the cache, even the classes that are not found. What can we do to prevent this?

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

Hi,

Which version of OWS are you using? Which version of Java is being used to run the Jnlp app? Can you please send us the log files? You can enable logging : https://openwebstart.com/docs/OWSGuide.html#_logging. Also switch on log content of Jnlp file.

In the stack trace there are several missing classes

Code: Select all

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.geotools.referencing.cs.DefaultCoordinateSystemAxis
...
 Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated". java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated     at 
 ...
 Caused by: java.lang.IllegalArgumentException: NumberSystem tech.units.indriya.function.DefaultNumberSystem not found 
Can you please try running the app after clearing the OWS application cache at <User Home>/.cache/cedtea-web/cache

In addition, just for the sake of trying, can you please try running with OWS 3.0.0 alpha https://github.com/karakun/OpenWebStart ... 0.0-alpha2

Thanks

Janak

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

Here is the information:
ows: 1.5.2
java: oracle_1.8.0_171
There is no difference after clearing the cache and with OWS 3.0.0 alpha.

Log files are sent to openwebstart@karakun.com

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

Thanks for the logs. But you did not enable Logging of Jnlp file.

However, from the stage 2 log I can see some issues:

At line 65 and line 91 : Ignoring java-vm-args due to illegal Property -Dlog4j.configDebug=true

OWS is ignoring all the java-vm-args specified in the jnlp because it does not recognize the above property. You need to add the arg to the jvm arg whitelist:

https://openwebstart.com/docs/OWSGuide. ... _arguments

Later there are errors:

Code: Select all

[ITW-APP ][2022-04-01 06:21:13.404 MESZ][ERROR][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)] SLF4J: Class path contains multiple SLF4J bindings.
This means there are duplicate classes on the class path in different jar files.

Moreover you application has an HTTP 401 error:

Code: Select all

[ITW-APP ][2022-04-01 06:21:40.743 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)] ERROR (AbstractOpenWebService.java:480) - Failed to execute request https://geoservices.bayern.de/wms/v2/ogc_dop20_datenabgabe.cgi?REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS
[ITW-APP ][2022-04-01 06:21:40.776 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (HttpMethodDirector.java:326) - Required proxy credentials not available for BASIC <any realm>@www-proxy.bybn.de:80
[ITW-APP ][2022-04-01 06:21:40.778 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (HttpMethodDirector.java:328) - Preemptive authentication requested but no default proxy credentials available
...
(AbstractOpenWebService.java:480) - Failed to execute request https://geoservices.bayern.de/wfs/v1/ogc_hauskoordinaten.cgi?REQUEST=GetCapabilities&SERVICE=WFS
[ITW-APP ][2022-04-01 06:22:01.580 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (DataAccessFinder.java:120) - Web Feature Server (NG) should be used, but could not connect
java.io.IOException: Server returned HTTP error code 401 for URL https://geoservices.bayern.de/wfs/v1/ogc_hauskoordinaten.cgi?REQUEST=GetCapabilities&SERVICE=WFS
Then ServiceLoader is failing:

Code: Select all

[ITW-APP ][2022-04-01 06:22:01.623 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (HttpMethodDirector.java:326) - Required proxy credentials not available for BASIC <any realm>@www-proxy.bybn.de:80
[ITW-APP ][2022-04-01 06:22:01.625 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (HttpMethodDirector.java:328) - Preemptive authentication requested but no default proxy credentials available
[ITW-APP ][2022-04-01 06:22:08.242 MESZ][INFO ][sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)]  WARN (FactoryRegistry.java:1114) - Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated".
java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated
	at java.util.ServiceLoader.fail(Unknown Source)
Then there are a number of NoClassDefFoundError:

Code: Select all


Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.geotools.referencing.factory.epsg.CartesianAuthorityFactory

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.geotools.referencing.cs.DefaultCoordinateSystemAxis
Could it be that there are duplicates of the classes in old and new versions of jars on the classpath?

.

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

Adding the properties did not bring any change.

The HTTP 401 error only occurs because the request is first made without a password. This has nothing to do with this.

The ServiceLoader and the NoClassDefFoundError should belong together and be the cause of the problem. I have checked the jars, but nothing is duplicated. It is also important to note again that sometimes it works.

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

Adding the properties did not bring any change
.

So now is your application starting with all the specified jvm-args?
It is also important to note again that sometimes it works.
Could it be that there is n old and new version of the class in different jars and that it is dependent on the order in which the class loader is loading the class from the jars.

Are you able to start the app with java from command line by specifying all the jars on the classpath?

Can you please send the jnlp file or the log wfile that has logged the contents of the jnlp file?

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

So now is your application starting with all the specified jvm-args?
Yes
Could it be that there is n old and new version of the class in different jars and that it is dependent on the order in which the class loader is loading the class from the jars.
I looked for it, but the classes don't seem to be duplicated.
Are you able to start the app with java from command line by specifying all the jars on the classpath?
Yes, it starts and works. Likewise in Eclipse and the Oracle web start.
Can you please send the jnlp file or the log wfile that has logged the contents of the jnlp file?
Files are sent. Also log files on a case that worked.

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

I compared the logs of non-working and working instances. The only difference I see is that the order in which jars are downloaded is different. May be this leads to different class loading in case there are duplicate classes.

I presume that all jars specified in the jnlp are also in the class path of the eclipse project. Can you check in your IDE (Eclipse) by searching the missing classes on the project's classpath? Eclipse search for type will display all version of the class on the class path.

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

I looked at the dependencies again, but nothing is duplicated. Also, I tried different things when building the project, but the error keeps coming up.

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

It is strange when you say it works sometime and sometime there is a NoClassDefFoundError.

Can you please try running it like the following:

Code: Select all

C:\Users\zapf_da\.cache\icedtea-web\jvm-cache\oracle_1.8.0_171\bin\java.exe -classpath C:\Users\zapf_da\.cache\icedtea-web\cache\0\2\afisnavigator-7.0.0-SNAPSHOT.jar;... de.bayern.lvg.apps.afisnavigator.MainClass -dbmappings service.db.connectiondata.ora1prod.jdbc,service.db.connectiondata.ora1ent2.jdbc
Basically, run the app by putting the jars in the OWS cache on the classpath. The jars and their paths can be extracted from the stage2 log file.

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

I started it from the command line as suggested. The result is that it worked every time I tried.
So it can only be due to a bug in OWS.

sg431
Posts: 12
Joined: 21 Mar 2022, 08:17

Re: NoClassDefFoundError

Post by sg431 »

Is there anything else I can do here now?

Janak Mulani
Posts: 500
Joined: 24 Mar 2020, 13:37

Re: NoClassDefFoundError

Post by Janak Mulani »

Since we cannot reproduce this issue, we will need to go deeper into this and try your app with the specified jar files. Request you to buy paid support so that we can allocate dedicated resources to look into this issue.

Post Reply