users@jersey.java.net

RE: [Jersey] JAXB schemagen ant task and namespaces (Help Jakub :-)

From: Rabick, Mark A (IS) <"Rabick,>
Date: Wed, 29 Apr 2009 09:49:07 -0500

I worked some of it out. I didn't have a namespace in the
package-info.java so it is now:
 
        @javax.xml.bind.annotation.XmlSchema (
                namespace="http://www.cnodb.mil/v1",
                xmlns = {
                        @javax.xml.bind.annotation.XmlNs(prefix =
"cnodb-v1",
                                namespaceURI="http://www.cnodb.mil/v1"),
                        @javax.xml.bind.annotation.XmlNs(prefix="xs",
        
namespaceURI="http://www.w3.org/2001/XMLSchema")
                }
        )
        package mil.cnodb.rs.model.v1;

Now the ant target for schemagen with the nested schema element produces
the desired output.

                        <target name="build.xml.schema" depends="init">
                                <schemagen
srcdir="src/com/cnodb/rs/model"
        
destdir="build/schemas">
                                        <schema
namespace="http://www.cnodb.com/v1" file="cnodb-v1.xsd"/>
                                </schemagen>
                        </target>

I had to make sure all of my XmlRootElement annotations did not specify
the namespace attribute (in favor of the package level namespace above)
or explicitly indicated the 'default' namespace.

@XmlRootElement(name="link", namespace="##default")

I posted this to Jersey because I had a follow up question on producing
extended WADL-s with schema information but I'm still working that
process.

-mark
_______________________________________________
Mark A. Rabick - Software Engineer
Em: mark.rabick_at_ngc.com

 


________________________________

        From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
        Sent: Wednesday, April 29, 2009 1:38 AM
        To: users_at_metro.dev.java.net
        Cc: users_at_jersey.dev.java.net
        Subject: Fwd: [Jersey] JAXB schemagen ant task and namespaces
(Help Jakub :-)
        
        
        Hi Mark,

        Cross posting to the metro users list.

        Paul.
        

        Begin forwarded message:


                From: "Rabick, Mark A (IS)" <Mark.Rabick_at_ngc.com>
                Date: April 28, 2009 7:39:39 PM CEDT
                To: users_at_jersey.dev.java.net
                Subject: [Jersey] JAXB schemagen ant task and namespaces
(Help Jakub :-)
                Reply-To: users_at_jersey.dev.java.net


                I have a set of JAXB annotated java classes that I'm
trying to generate an XSD schema from. I'm trying to change the default
output generated file from schema1.xsd with no success. The classes are
in the directory:

                src/com/cnodb/rs/model

                In the file:
src/com/cnodb/rs/model/v1/package-info.java

                I have a packege level JAXB XmlSchema annotation:

                        @javax.xml.bind.annotation.XmlSchema (
                              xmlns = {
                                @javax.xml.bind.annotation.XmlNs(prefix
= "cnodb-v1",
        
namespaceURI="http://www.cnodb.com/v1"),

        
@javax.xml.bind.annotation.XmlNs(prefix="xs",
        
namespaceURI="http://www.w3.org/2001/XMLSchema")
                              }
                        )
                        package com.cnodb.rs.model.v1;

                The ant task is defined in my build.xml as follows:

                        <taskdef name="schemagen"
classname="com.sun.tools.jxc.SchemaGenTask">
                          <classpath>
                                <path refid="Web App
Libraries.libraryclasspath"/>
                                <path refid="JAXB Build
Support.userclasspath"/>
                          </classpath>
                        </taskdef>

                The ant target calling schemagen is:

                        <target name="build.xml.schema" depends="init">
                                <schemagen
srcdir="src/com/cnodb/rs/model"
        
destdir="build/schemas">
                                        <schema
namespace="http://www.cnodb.com/v1" file="cnodb-v1.xsd"/>
                                </schemagen>
                        </target>

                According to the JAXB site at:
https://jaxb.dev.java.net/nonav/2.1.11/docs/schemagenTask.html
<https://jaxb.dev.java.net/nonav/2.1.11/docs/schemagenTask.html>

                The nested schema element under the schemagen invocation
should produce the output file cnodb-v1.xsd for my defined namespace but
the target is producing the default file "schema1.xsd".

                I can workaround this by just renaming the file at
present because I have a single namespace but we may be federating our
namespaces because of some shared elements with another project.

                I have the JAXB 2.1 distribution
https://jaxb.dev.java.net/2.1.10/JAXB2_20090206.jar
<https://jaxb.dev.java.net/2.1.10/JAXB2_20090206.jar>

                A final note, none of the sample JAXB apps use the
nested schema element.

                Using JDK 1.6.0_12.

                --mark
                _______________________________________________
                Mark A. Rabick
                Em: mark.rabick_at_ngc.com