users@jaxb.java.net

RE: JAXB compilation plugin

From: Jonathan Johnson <jonjohnson_at_mail.com>
Date: Sat, 4 Mar 2006 22:03:22 -0500

    I used to put all of my XSD files under src/conf and distributed them
into the root of the jar. As such, PatternFilenameFilter and
GlobFilenameFilter would both work well.

    I noticed that the XJC jar had the binding.xsd under
/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd inside the jar.
This is actually really good because it prevent classloader problems of
finding the wrong one by some other company. I started to modify the
resources section of my pom.xml, and realized there was a much easier way.

    I have now moved all of my XSD files directly into the source directory.
In the IDE, they show up as a resource in that package/namespace, and the
resources part of the pom.xml automatically can copy them into the correct
directory without any sophisticated filename mapping.

    [jon] I agree that schemas should be placed in a package structure that
matches the source, but the schemas and bindings and any other resource file
should not live in the java tree. Instead the schemas and code should live
in the parallel packages at distinct source roots. For example

    \src\main\java\com\sun\foo\someclass.java
    \src\main\schemas\com\foo\somecorresponding.xsd
    When assembling a jar, yes the class files live in the same location as
the xsd, but the java and xsd sources should be kept separate as a best
practice.

  I can see that. Maven's docs say that there should be a "resources"
directory. Do you think we should use that, or do you think that the
XSDs/XJBs need their own "schemas" directory. I ask, because, what if they
are using DTD? That isn't technically schema, but should go in the same
place.

  [jon] Resources are really meant for those items that are loaded by the
classloader at runtime. Items in the resources tree are bundled into the
distribution jar just as the *.classes are. Typical files are string
bundles, and images directory, static property files, sound files, data
files, etc. Schemas are used at compile time and not typically loaded at
runtime from the classpath. *.xsd, *.dtd and *.xsb are compile time
articfacts and should be kept separate from the runtime artifacts.

  The choice of the term "schemas" for the directory name was intentional.
Schema is a generic term and has been used longer than the invention of
*.xsd files. Both *.xsd and *.dtd are based on the original concepts
founded in database 'schemas'. The *.xsb files are also artifacts that
define a schema. A DTD is a data schema. A *.xsd file is a data schema and
a captial S, Schema. The schema directory name here is meant in a more
general sense. The Jaxme folks opted to call their directory
\src\main\jaxme, but I thought that was too specific since you may have
other schemas that are not used for jaxme but want them in the same,
consistent place.

  So, I see the src/main/schema directory makes sense.