{"id":1244,"date":"2013-02-23T23:54:36","date_gmt":"2013-02-23T22:54:36","guid":{"rendered":"https:\/\/bob-team.de\/wordpress\/?p=1244"},"modified":"2013-04-13T10:07:05","modified_gmt":"2013-04-13T08:07:05","slug":"jaxb2-xmlrootelement-xjc","status":"publish","type":"post","link":"https:\/\/bob-team.de\/wordpress\/2013\/02\/23\/jaxb2-xmlrootelement-xjc\/","title":{"rendered":"JAXB2, @XmlRootElement, XJC"},"content":{"rendered":"<p>Ist im Schema der XSD-Datei der Wurzelknoten per <tt>complexType<\/tt> beschrieben, muss dem <tt>xjc<\/tt> mitgeteilt werden, welche Klasse die <tt>XmlRootElement<\/tt>-Annotation bekommt. Mit <a href=\"http:\/\/confluence.highsource.org\/display\/J2B\/Downloads\">JAXB2 Basic<\/a> erh\u00e4lt man eine komplette Sammlung aller notwendigen Bibliotheken. Das Projekt erweitert die Referenzimplementierung um Tools, die eine Anpassung per XJB-Datei erm\u00f6glicht. Im folgenden Beispiel wird der Typ <tt>Foo<\/tt> zum Wurzelknoten und das Paket <tt>bob.demo<\/tt> per <a href=\"http:\/\/ant.apache.org\/\">Ant<\/a> gesetzt.<!--more--><\/p>\n<p>[code lang=&#8220;xml&#8220;]<?xml version=\"1.0\" encoding=\"UTF-8\"?><br \/>\n<schema targetNamespace=\"http:\/\/www.bob-team.de\/demo\" \n\t\telementFormDefault=\"qualified\" \n\t\txmlns=\"http:\/\/www.w3.org\/2001\/XMLSchema\" \n\t\txmlns:bob=\"http:\/\/www.bob-team.de\/demo\"><br \/>\n    <element name=\"FOO\" type=\"bob:Foo\"><br \/>\n    <\/element><br \/>\n    <complexType name=\"Foo\"><br \/>\n    \t<simpleContent><br \/>\n    \t\t<extension base=\"string\"><br \/>\n    \t\t\t<attribute name=\"type\" type=\"string\"><\/attribute><br \/>\n    \t\t<\/extension><br \/>\n    \t<\/simpleContent><br \/>\n    <\/complexType><br \/>\n<\/schema>[\/code]<\/p>\n<p>[code lang=&#8220;xml&#8220;]<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><br \/>\n<jaxb:bindings \n\t\tversion=\"2.1\"\n\t\txmlns:jaxb=\"http:\/\/java.sun.com\/xml\/ns\/jaxb\"\n\t\txmlns:xs=\"http:\/\/www.w3.org\/2001\/XMLSchema\"\n\t\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\t\txmlns:bob=\"http:\/\/www.bob-team.de\/demo\"\n\t\txmlns:annox=\"http:\/\/annox.dev.java.net\"\n\t\tjaxb:extensionBindingPrefixes=\"bob annox\"><br \/>\n\t<jaxb:bindings schemaLocation=\"demo.xsd\" node=\"\/xs:schema\/xs:complexType[@name = 'Foo']\"><br \/>\n\t\t<annox:annotate><br \/>\n\t\t\t<annox:annotate annox:class=\"javax.xml.bind.annotation.XmlRootElement\"\/><br \/>\n      \t\t<\/annox:annotate><br \/>\n\t<\/jaxb:bindings><br \/>\n\t<jaxb:bindings schemaLocation=\"demo.xsd\" node=\"\/xs:schema\"><br \/>\n        \t<jaxb:schemaBindings><br \/>\n            \t\t<jaxb:package name=\"bob.core.demo\"\/><br \/>\n        \t<\/jaxb:schemaBindings><br \/>\n    \t<\/jaxb:bindings><\/p>\n<p><\/jaxb:bindings>[\/code]<\/p>\n<p>[code lang=&#8220;xml&#8220;]<?xml version=\"1.0\"?>\n<project name=\"jaxb2-basics-sample-po-ant\" default=\"generate-sources\">\n\t<property name=\"JAXB_HOME\" value=\"C:\/jaxb2-basics-dist-0.6.3\"\/>\n\t<target name=\"generate-sources\"><br \/>\n\t\t<taskdef name=\"xjc\" classname=\"org.jvnet.jaxb2_commons.xjc.XJC2Task\"><br \/>\n\t\t\t<!-- XJC2 Task classpath --><br \/>\n\t\t\t<classpath><br \/>\n\t\t\t\t<fileset dir=\"${JAXB_HOME}\"><br \/>\n\t\t\t\t\t<include name=\"activation-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb-api-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb-impl-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jsr173_api-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"stax-api-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb2-basics-jaxb-xjc-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb-xjc-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb2-basics-ant-*.jar\"\/><br \/>\n\t\t\t\t<\/fileset><br \/>\n\t\t\t<\/classpath><br \/>\n\t\t<\/taskdef><br \/>\n\t\t<mkdir dir=\"${basedir}\/src\"\/><br \/>\n\t\t<xjc destdir=\"${basedir}\/src\" extension=\"true\"><br \/>\n\t\t\t<arg line=\"\n\t\t\t\t-Xannotate\"\/><br \/>\n\t\t\t<binding dir=\"${basedir}\"><br \/>\n\t\t\t \t<include name=\"**\/*.xjb\"\/><br \/>\n\t\t\t<\/binding><br \/>\n\t\t\t<schema dir=\"${basedir}\"><br \/>\n\t\t\t \t<include name=\"**\/*.xsd\"\/><br \/>\n\t\t\t<\/schema><br \/>\n\t\t\t<!-- Plugins --><br \/>\n\t\t\t<classpath><br \/>\n\t\t\t\t<fileset dir=\"${JAXB_HOME}\"><br \/>\n\t\t\t\t\t<!-- JAXB2 Basics library --><br \/>\n\t\t\t\t\t<include name=\"jaxb2-basics-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"jaxb2-basics-annotate*.jar\"\/><br \/>\n\t\t\t\t\t<!-- JAXB2 Basics library dependencies --><br \/>\n\t\t\t\t\t<include name=\"annox-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"hibernate-search-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"commons-logging-*.jar\"\/><br \/>\n\t\t\t\t\t<include name=\"commons-lang-*.jar\"\/><br \/>\n\t\t\t\t<\/fileset><br \/>\n\t\t\t<\/classpath><br \/>\n\t\t<\/xjc><br \/>\n\t<\/target>\n<\/project>[\/code]<\/p>\n<p>Weitere Details: <a href=\"http:\/\/www.javaworld.com\/community\/node\/8101\">http:\/\/www.javaworld.com<\/a> und <a href=\"http:\/\/docs.oracle.com\/cd\/E17802_01\/webservices\/webservices\/docs\/1.5\/tutorial\/doc\/JAXBUsing4.html\">Customizing JAXB Bindings<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ist im Schema der XSD-Datei der Wurzelknoten per complexType beschrieben, muss dem xjc mitgeteilt werden, welche Klasse die XmlRootElement-Annotation bekommt. Mit JAXB2 Basic erh\u00e4lt man eine komplette Sammlung aller notwendigen Bibliotheken. Das Projekt erweitert die Referenzimplementierung um Tools, die eine Anpassung per XJB-Datei erm\u00f6glicht. Im folgenden Beispiel wird der Typ Foo zum Wurzelknoten und das [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[55,81],"class_list":["post-1244","post","type-post","status-publish","format-standard","hentry","category-java","tag-ant","tag-jaxb","entry"],"_links":{"self":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/comments?post=1244"}],"version-history":[{"count":6,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1244\/revisions"}],"predecessor-version":[{"id":1291,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1244\/revisions\/1291"}],"wp:attachment":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/categories?post=1244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/tags?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}