users@jaxb.java.net

Antwort: Re: Re: how to avoid duplicated (generated) classes?

From: <torsten.reinhard_at_gi-de.com>
Date: Wed, 17 Dec 2008 11:03:20 +0100

Hi, sorry again,

I couldnīt get that to work, let me show you what Iīve tried until now:

a.xsd is like

<schema targetNamespace="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        xmlns:gematik="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        xmlns="http://www.w3.org/2001/XMLSchema"
        ...>

        <include schemaLocation="a-types.xsd"/>
        <element name="gematikMsg">

b.xsd is like

<schema targetNamespace="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        xmlns:gematik="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        xmlns="http://www.w3.org/2001/XMLSchema"
        ...>

        <include schemaLocation="a-types.xsd"/>
        <element name="gematikMsgRueck">

a-types.xsd (included by a.xsd and b.xsd) is like

<schema ...
        xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
        xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
        xmlns:gematik="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="
http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        ...>
        <import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="../xmldsig-core-schema.xsd"/>
        <import namespace="http://www.w3.org/2001/04/xmlenc#"
schemaLocation="../xenc-schema.xsd"/>

Now, my XJC-Task :

<xjc destdir="${project.basedir}/${target.dir}/generated-sources/java"
removeOldOutput="yes" >
         <binding dir="src/main/resources/schemas">
                <include name="bindings.xjb"/>
                <include name="vsd51/bindings.xjb"/>
        </binding>

        <schema dir="src/main/resources/schemas/ed4gm51">
                <include name="a.xsd" />
                <include name="b.xsd" />
        </schema>
        <arg value="-extension" />
</xjc>

==> This works fine - all generated sources are placed to
\target\generated-sources\java\de\gematik\ws\schema\personalisierung - as
expected from the namespace.

I want to change that location, so I tried:

        <xjc
destdir="${project.basedir}/${target.dir}/generated-sources/java"
removeOldOutput="yes" package="com.mycompany.test">
        ...
and I got:
        [xjc] [ERROR] A class/interface with the same name
"com.mycompany.test.KeyValueType" is already in use. Use a class
customization to resolve this conflict.

So I tried to define the package via separate bindings files, defining the
same package:

        <xjc
destdir="${project.basedir}/${target.dir}/generated-sources/java"
removeOldOutput="yes">
                 <binding dir="src/main/resources/schemas">
                <include name="bindings.xjb"/>
                <include name="vsd51/bindings.xjb"/>
                <include name="ed4gm51/binding_a.xjb"/>
                <include name="ed4gm51/binding_b.xjb"/>
        </binding>

binding_a.xjb:
  <jxb:bindings schemaLocation="a.xsd" node="/xs:schema">
    <jxb:schemaBindings>
      <jxb:package name="com.mycompany.test"/>
    </jxb:schemaBindings>
  </jxb:bindings>

binding_b.xjb
  <jxb:bindings schemaLocation="b.xsd" node="/xs:schema">
    <jxb:schemaBindings>
      <jxb:package name="com.mycompany.test"/>
    </jxb:schemaBindings>
  </jxb:bindings>

and I got:
        [xjc] [ERROR] Multiple <schemaBindings> are defined for the target
namespace "http://ws.gematik.de/schema/Personalisierung/ed414/v5.2"
        [xjc] line 12 of
file:...../src/main/resources/schemas/ed4gm51/binding_b.xjb
        [xjc]
        [xjc] [ERROR] Another <schemaBindings> is defined here


=> what am I doing wrong ?

Thanx, torsten




"Wolfgang Laun" <wolfgang.laun_at_gmail.com>
11.12.2008 15:09

An
torsten.reinhard_at_gi-de.com
Kopie

Thema
Re: Re: how to avoid duplicated (generated) classes?






Just get rid of the binding specs putting the common stuff into
different packages, and you'll be fine.

We've been using common schema files since day 1, and we never had a
problem. Probably using a separate namespace for the import is a good
idea so you don't run into name clashes later on.

HTH
W



On Thu, Dec 11, 2008 at 2:30 PM, <torsten.reinhard_at_gi-de.com> wrote:
>
> yes, iīm familiar with xs:import - thatīs currently used in our project.
>
> src\main\resources\a\
> - a.xsd
> - a-types.xsd
> - common.xsd
> - person.xsd
> - adress.xsd
>
> src\main\resources\b\
> - b.xsd
> - b-types.xsd
> - common.xsd
> - person.xsd
> - adress.xsd
>
> whera a.xsd has an import on the other *.xsd and b.xsd has an import on
the
> other *.xsd
>
> But actually, the common.xsd, person.xsd and adress.xsd in each
subproject
> has its own "binding.xjb" file, which binds the classes to different
> packages (depending on the parent folder)
>
> I see 2 options to solve this:
> a) let all bindings.xjb files point to the same package, for example
> com.mycompany.shared for common.xsd, person.xsd and adress.xsd
> - the classes will still be generated several times (what you
call
> waste of cycles) but always in the same package/directory and therefore
only
> one times in the resulting jar.
> b) use "episode" files (what i read a few minutes ago) to tell the
compiler
> which classes are already there.
>
> I think "wasting cycles" is the easier way:-)
>
> thanx, Torsten
>
>
>
>
> "Wolfgang Laun" <wolfgang.laun_at_gmail.com>
>
> 11.12.2008 14:13
>
> An
> torsten.reinhard_at_gi-de.com
> Kopie
> Thema
> Re: how to avoid duplicated (generated) classes?
>
>
>
>
> I was assuming that you are familiar with
> <xs:import namespace="..." schemaLocation="..."/>
> to include a common schema definition in other schemas.
>
> Or is/was this your problem?
>
> -W
>
> On Thu, Dec 11, 2008 at 12:38 PM, <torsten.reinhard_at_gi-de.com> wrote:
>>
>> Hi,
>>
>> I have some separate *.xsd structures, sharing all the same common
*.xsd
>> structure:
>>
>> A.xsd
>> +- a-Types.xd
>> +- common.xsd
>> +- person.xsd
>> +- adress.xsd
>> +- ...xsd
>>
>> B.xsd
>> +- b-Types.xd
>> +- common.xsd
>> +- person.xsd
>> +- adress.xsd
>> +- ...xsd
>>
>> What I finally want is the following packages, containing the (XJC)
>> generated JAXB classes:
>>
>> com.mycompany.a
>> com.mycompany.b
>> com.mycompany.common
>> com.mycompany.person
>> com.mycompany.adress
>>
>> How can I avoid common.xsd, person.xsd and adress.xsd being generated
>> multiple times?
>>
>> thanx, Torsten
>>
>>
>
>