简体   繁体   中英

RuntimeException from xmlbeans - can't find compiled schema

I'm getting a RuntimeException while executing some code that depends on generated xmlbeans classes. I can't figure out if this is:

  • me missing something during code-generation or packaging
  • a runtime dependency missing
  • a misleading error message, and I should be looking elsewhere.

The xbean.jar version is the same in the build and execution environment. Anyone seen this before or have any ideas?

Thanks.

...snip...
Caused by: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?
    at schemaorg_apache_xmlbeans.system.s2B8331230CBD98F4933B0B025B6BF726.TypeSystemHolder.loadTypeSystem(Unknown Source)
    at schemaorg_apache_xmlbeans.system.s2B8331230CBD98F4933B0B025B6BF726.TypeSystemHolder.(Unknown Source)
    ... 38 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    ... 40 more
Caused by: org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/s2B8331230CBD98F4933B0B025B6BF726/index.xsb (schemaorg_apache_xmlbeans.system.s2B8331230CBD98F4933B0B025B6BF726.index) - code 0
    at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.(SchemaTypeSystemImpl.java:1504)
    at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:260)
    at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.(SchemaTypeSystemImpl.java:183)
    ... 44 more
...snip...

The answer of John was a good hint for me. I generated Java classes with xmlBeans and copied the source files out of the "noNamespace" manually in my project to modify them. unfortunately I did not recognize that there were also generated class files in the "schemaorg_apache_xmlbeans" folder and did not copy them.
After switching to the usage of the generated jar-file everything worked fine for me.

I've never used the library before but I can kind of guess at what's going on. With that qualifier (ie, I'm just making this up, but it's been 7 hours and no one else has made anything up)...

Stating the obvious: something has been compiled somewhere and can't be loaded. I don't think this something is in the jar file; I'm guessing it's one of your resources that's been compiled/cached to some location.

I would guess either:

  • it's compiled in a place it's not loadable from (messed up classpath/config)
  • the versioning is wrong between what's been compiled and what wants to be loaded

Did you change something (eg schema version?) between the compilation and loading/running?

Can you remove the compiled version and recompile and then try a reload?

Can you locate the compiled version in the file system?

To do this, you might try

grep "s2B8331230CBD98F4933B0B025B6BF726" `find .`

from some suitable directory.

Can you do an an md5 on the class/resource causing problems in both compile and runtime environments? Do they match?

Hope something in there helps or triggers a thought.

I have seen this problem often when there was a script (ant, maven, ...) that would handle the XMLBeans compilation and another mechanism was used for compiling and running the rest of the code. Sometimes one piece will delete the generated files that XMLBeans is looking for in your stack trace, but will leave the generated XMLBeans Java files so everything will compile and look fine.

I have also seen this when using the option to output the source files, but not the class files. The non-Java source files are only generated directly into the class folder or jar file generated by XMLBeans.

These class files are generated in the resources/schemaorg_apache_xmlbeans directory. I have seen xmlbeans behaviour where the generated ant script has failed to include this directory in the jar it creates (perhaps due to a bug?) Check that it has been included in the jar. You could manually re-jar, or check your code generation commandline options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM