我在java中使用KML对象。我想将此对象导出到文件。我试着用JAK库编写这个,使用函数KML.marshal(),但它不是successFul。 我收到这个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/bind/marshaller/NamespacePrefixMapper
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at de.micromata.opengis.kml.v_2_2_0.Kml.createMarshaller(Kml.java:642)
at de.micromata.opengis.kml.v_2_2_0.Kml.marshal(Kml.java:682)
at de.micromata.opengis.kml.v_2_2_0.Kml.marshal(Kml.java:759)
at com.nice.nicetrack.KMLGenerator.toKML(KMLGenerator.java:141)
at com.nice.nicetrack.KMLGenerator.main(KMLGenerator.java:240)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.marshaller.NamespacePrefixMapper
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
我不想使用XML或String格式。只有KMl对象!! 请帮我!! 谢谢!
答案 0 :(得分:0)
JAK依赖于用于基础XML序列化的XML绑定的Java体系结构(JAXB)。 KML是一种XML格式,因此您必须将JAXB jar添加到类路径中。
jaxb-api-2.2.jar
jaxb-impl-2.2.jar
可以在项目的POM.XML中找到这些依赖项。 https://github.com/micromata/javaapiforkml/blob/master/pom.xml
如果使用maven构建,可以将jaxb条目直接添加到pom.xml文件中,但如果添加 JavaAPIforKml 条目,则应自动下载它们,如下所示:
<dependency>
<groupId>de.micromata.jak</groupId>
<artifactId>JavaAPIforKml</artifactId>
<version>2.2.1</version>
</dependency>
否则,您可以直接在Central Maven存储库中搜索jar:
https://search.maven.org/#browse