Error when using XmlBeans generated classes
Asked Answered
P

6

13

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?

Pollination answered 15/12, 2011 at 10:7 Comment(0)
A
5

In your generated jar file make sure you have included the class files generated from your xmlbeans.

From the stacktrace :

Caused by: java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.s8
B21CFFFCFED0B2438C2585C61F113F7.TypeSystemHolder

it suggests that during compile time the required class files are in classpath but in your built jar these files are missing.

Check your jar file to see if these classes are present.

EDIT: As per question rephrased

For building jar with dependecies in Maven use jar-with-dependencies option, example

Two very good reference :

  1. http://www.sonatype.com/books/mvnref-book/reference/assemblies-sect-basics.html

  2. http://thomassundberg.wordpress.com/2011/03/05/create-an-executable-jar-from-maven/

In the second one you don't need a main class if your jar is not an executable jar

Ambit answered 15/12, 2011 at 10:33 Comment(4)
I've refrased my question to better explain what I needPollination
For building jar with dependencies you can use maven-assembly plugin where you need to specify which all jars it should include, sample pom can be found here maven.apache.org/plugins/maven-assembly-plugin/…Ambit
When you build a JAR project with Maven, the JAR only contains the classes from that project. It does not contain the JARs that were needed to build it, nor the JARs that will be needed to execute (mostly, but not always the same ones). If you packaged your project as a WAR or EAR, though, Maven would include all the JARs that your POM lists as runtime dependencies. If you don't need a WAR or EAR, then the assembly-plugin suggestion above is simpler (use the jar-with-dependencies option).Berni
Your answer was very helpful but still I was unable to make it work for me since the maven-assembly plugin only includes jars that are installed in its repository and are defined as a dependency. SInce i has a self generated jar from the XmlBeans i included it using the system dependency, but as it turns out, the assembly plugin does not include system dep. in the jar file. so i just installed the jar in maven repository and included it as regular dependency and everything worked like a charm.Pollination
E
12

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.

Endogen answered 16/12, 2013 at 5:59 Comment(0)
A
5

In your generated jar file make sure you have included the class files generated from your xmlbeans.

From the stacktrace :

Caused by: java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.s8
B21CFFFCFED0B2438C2585C61F113F7.TypeSystemHolder

it suggests that during compile time the required class files are in classpath but in your built jar these files are missing.

Check your jar file to see if these classes are present.

EDIT: As per question rephrased

For building jar with dependecies in Maven use jar-with-dependencies option, example

Two very good reference :

  1. http://www.sonatype.com/books/mvnref-book/reference/assemblies-sect-basics.html

  2. http://thomassundberg.wordpress.com/2011/03/05/create-an-executable-jar-from-maven/

In the second one you don't need a main class if your jar is not an executable jar

Ambit answered 15/12, 2011 at 10:33 Comment(4)
I've refrased my question to better explain what I needPollination
For building jar with dependencies you can use maven-assembly plugin where you need to specify which all jars it should include, sample pom can be found here maven.apache.org/plugins/maven-assembly-plugin/…Ambit
When you build a JAR project with Maven, the JAR only contains the classes from that project. It does not contain the JARs that were needed to build it, nor the JARs that will be needed to execute (mostly, but not always the same ones). If you packaged your project as a WAR or EAR, though, Maven would include all the JARs that your POM lists as runtime dependencies. If you don't need a WAR or EAR, then the assembly-plugin suggestion above is simpler (use the jar-with-dependencies option).Berni
Your answer was very helpful but still I was unable to make it work for me since the maven-assembly plugin only includes jars that are installed in its repository and are defined as a dependency. SInce i has a self generated jar from the XmlBeans i included it using the system dependency, but as it turns out, the assembly plugin does not include system dep. in the jar file. so i just installed the jar in maven repository and included it as regular dependency and everything worked like a charm.Pollination
S
4

Please add below tag in pom.xml. Error wil go

        <!--
            this tells maven to copy the openejb-javaagent jar into your target/
            directory
        -->
        <!-- where surefire can see it -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.apache.openejb</groupId>
                                <artifactId>openejb-javaagent</artifactId>
                                <version>3.0-beta-2</version>
                                <outputDirectory>${project.build.directory}</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>target/generated-sources/axis2/wsdl2code/resources</directory>
        </resource>
        <resource>
            <directory>target/generated-sources/xmlbeans/resources</directory>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>
Sympathize answered 4/12, 2012 at 5:22 Comment(0)
S
4

When you have this kind of error The TypeSystemHolder.class generated by WSDL2Java is not be placed in your classpath in order to avoid this error.

Please copy TypeSystemHolder.class from "resource/schemaorg_apache_xmlbeans/system/s68C41DB812F52C975439BA10FE4FEE54" folder.

And Paste TypeSystemHolder.class file into your classpath folder (build/classes/schemaorg_apache_xmlbeans/system/s68C41DB812F52C975439BA10FE4FEE54) folder

Subduct answered 16/1, 2013 at 13:15 Comment(0)
D
0

Extract jar in which you want to include schemaorg_apache_xmlbeans folder. Copy schemaorg_apache_xmlbeans folder in extracted folder (result from jar extraction). open command prompt in extracted folder.

make jar again using jar cf command. e.g jar cf test.jar *, to include all folders.

Deploy that jar .

Dialecticism answered 7/7, 2017 at 16:9 Comment(0)
L
0

I meet this problem. In our project we use customize classloader to compatible poi old version. when parse '.xlsx' file ,It's occurs the same error. follow is the origin code

    private static String EXCEL_PATH = "com.alibaba.excel";
    private static String POI_PATH = "org.apache.poi";
    private static String OOXML_PATH="org.openxmlformats.schemas";
    private static String MICRO_OOXML_PATH="com.microsoft.schemas";
    private static String SCHEMAORG_APACHE_XMLBEANS="schemaorg_apache_xmlbeans";    
 @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        if (name.startsWith(POI_PATH)
                || name.startsWith(EXCEL_PATH)
                || name.startsWith(OOXML_PATH)
                || name.startsWith(MICRO_OOXML_PATH)
          ) {
            synchronized (getClassLoadingLock(name)) {
    
                // First, check if the class has already been loaded
                Class<?> c = findLoadedClass(name);
                if (c == null) {
                    c = findClass(name);
                    if (c == null) {
                        throw new ClassNotFoundException("custom classloader can't find this class");
                    }
                }
                if (resolve) {
                    resolveClass(c);
                }
                return c;
            }
        } else {
            return oldClassLoader.loadClass(name);
        }
    }

we use customize classloader to load ooxml-schemes.jar,but schemaorg_apache_xmlbeans.system.s8 B21CFFFCFED0B2438C2585C61F113F7.TypeSystemHolder is not in our classloader load path ,default classloader load it . so i solved it by change my classloader code

protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        *// we change here to load schemaorg...*
        if (name.startsWith("schemaorg_apache_xmlbeans")
          ) {
        //todo 
           }
       //todo
    }

to loader this class ,then it's be ok

Leprosarium answered 9/10, 2021 at 8:44 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Tryck
I've changed the generation of the TypeSystemHolder class, i.e. it's now generated in the sources opposed to resources. There are actually more changes with XmlBeans 5.0.1, so it's time to drop the old ooxml-schema.jar and start using the new poi-ooxml-lite or poi-ooxml-full artifacts. The generated packages have also changed - this might need to be taken into account by your custom classloader.Troche

© 2022 - 2024 — McMap. All rights reserved.