Error when using XmlBeans generated classes

Tomer picture Tomer · Dec 15, 2011 · Viewed 34.8k times · Source

I've generated classes with XMLBeans from an xsd file and packed them in a jar file. then I've added that jar to the project classpath in eclipse and everything compiles and runs fine. I built a stand alone jar file from my project with Maven and again the build is successful, but when i try running it i get this error:

 Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.oblicore.oblisync.resolutions.TestsDocument$Factory.parse(TestsDo
cument.java:126)
    at com.oblicore.oblisync.handlers.TransferEntitiesHandler.getResolution(
TransferEntitiesHandler.java:117)
    at com.oblicore.oblisync.handlers.TransferEntitiesHandler.resolveConflic
ts(TransferEntitiesHandler.java:103)
    at com.oblicore.oblisync.main.Orchestrator.run(Orchestrator.java:107)
    at com.oblicore.oblisync.main.Orchestrator.main(Orchestrator.java:58)
Caused by: java.lang.RuntimeException: Cannot load SchemaTypeSystem. Unable to l
oad class with name schemaorg_apache_xmlbeans.system.s8B21CFFFCFED0B2438C2585C61
F113F7.TypeSystemHolder. Make sure the generated binary files are on the classpa
th.
    at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:7
83)
    at com.oblicore.oblisync.resolutions.TestsDocument.<clinit>(TestsDocumen
t.java:19)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.s8
B21CFFFCFED0B2438C2585C61F113F7.TypeSystemHolder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:7
69)
    ... 6 more

The missing class is in the jar i created with XmlBeans, how do i tell maven to add it to the jar it creates from my project?

Answer

Jahir picture Jahir · Dec 16, 2013

While doing WSDL2Java a directory named resources will be created. Copy the schemaorg_apache_xmlbeans which presents under resources to classpath of your project. This should be the fix.