使用XmlBeans生成的类时出错 [英] Error when using XmlBeans generated classes

查看:769
本文介绍了使用XmlBeans生成的类时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从xsd文件中使用XMLBeans生成了类,并将它们打包在jar文件中.然后,我将该罐子添加到了eclipse中的项目类路径中,一切都可以编译并运行良好. 我使用Maven从我的项目中构建了一个独立的jar文件,再次构建成功,但是当我尝试运行它时,出现此错误:

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

缺少的类在我使用XmlBeans创建的jar中,如何告诉Maven将其添加到从我的项目创建的jar中?

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?

推荐答案

在生成的jar文件中,确保已包含从xmlbeans生成的类文件.

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

从堆栈跟踪中:

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

它建议在编译时所需的类文件在classpath中,但是在您的内置jar中这些文件丢失了.

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

检查您的jar文件以查看是否存在这些类.

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

按问题改写

要在Maven中使用依赖项构建jar,请使用jar-with-dependencies选项,

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

两个很好的参考书:

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

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

在第二个中,如果您的jar不是可执行jar,则不需要主类

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

这篇关于使用XmlBeans生成的类时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆