# JavaTM Architecture for XML Binding
Binding Compiler (xjc)

Specification Version: 1.0
Reference Implementation (RI) Version: 1.0.6

Main: Release Notes | XJC | Ant task | Sample Apps | Changelog
JAXB RI Extensions: Runtime Properties | XJC Customizations
JAXB RI Schema Languages: W3C XML Schema | RELAX NG | DTD
JAXB Community: Java.net Homepage | Developer interest list | FAQ

### Launching xjc

The binding compiler can be launched using the appropriate `xjc` shell script in the `bin` directory for your platform. We also provide an Ant task to run the binding complier - see the instructions for using xjc with Ant.

> #### For Solaris/Linux

> > 1. `% export PATH=<your JWSDPN/A installation directory>/jaxb/bin:$JWSDP_HOME/jwsdp-shared/bin:$PATH`
> > 2. `% $JAXB_HOME/bin/xjc.sh -help`

> #### For WindowsNT/2000/XP

> > 1. `> set PATH=<your JWSDPN/A installation directory>\jaxb\bin;%JWSDP_HOME%\jwsdp-shared\bin;%PATH%`
> > 2. `> %JAXB_HOME%\bin\xjc.bat -help`

> #### Environment Variables

> > - XJC_OPTS - command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here. If you are using the xjc ant task, you would specify these options via the ANT_OPTS evironment variable.

> #### Output

> >     Usage: xjc [-options ...] <schemas>

> >     Options:
> >       -nv                :  do not perform strict validation of the input schema(s)
> >       -extension         :  allow vendor extensions - do not strictly follow the
> >                             Compatibility Rules and App E.2 from the JAXB Spec
> >       -b <file>          :  specify external bindings files (each <file> must have its own -b)
> >       -d <dir>           :  generated files will go into this directory
> >       -p <pkg>           :  specifies the target package
> >       -host <proxyHost>  :  set http.proxyHost property to <proxyHost>
> >       -port <proxyPort>  :  set http.proxyPort property to <proxyPort>
> >       -classpath <arg>   :  specify where to find user class files
> >       -catalog <file>    :  specify catalog files to resolve external entity references
> >                             support TR9401, XCatalog, and OASIS XML Catalog format
> >       -readOnly          :  generated files will be in read-only mode
> >       -use-runtime <pkg> :  suppress the generation of the impl.runtime package and simply
> >                             refer to another existing runtime in the specified package
> >       -xmlschema         :  treat input as W3C XML Schema (default)
> >       -relaxng           :  treat input as RELAX NG (experimental,unsupported)
> >       -dtd               :  treat input as XML DTD (experimental,unsupported)
> >       -quiet             :  suppress compiler output
> >       -help              :  display this help message
> >       -version           :  display version information

> #### Non-standard Commandline Options

> > These options are non-standard and may change without notice.

> >       -Xlocator          :  enable source location support for generated code
> >       -Xsync-methods     :  generate accessor methods with the 'synchronized' keyword

> #### Execute the `jaxb-xjc.jar` JAR File

> > If all else fails, you should be able to execute the `jaxb-xjc.jar` file:

> > > For Solaris/Linux:
> > >   `% java -jar <your JWSDPN/A installation directory>/jaxb/lib/jaxb-xjc.jar -help`
> > > For Windows:
> > >   `> java -jar <your JWSDPN/A installation directory>\jaxb\lib\jaxb-xjc.jar -help`

### Summary of Command Line Options

> -nv
>   By default, the XJC binding compiler performs strict validation of the source schema before processing it. Use this option to disable strict schema validation. This does not mean that the binding compiler will not perform any validation, it simply means that it will perform less-strict validation.
> -extension
>   By default, the XJC binding compiler strictly enforces the rules outlined in the Compatibility chapter of the JAXB Specification. Appendix E.2 defines a set of W3C XML Schema features that are not completely supported by JAXB v1.0. In some cases, you may be allowed to use them in the "-extension" mode enabled by this switch. In the default (strict) mode, you are also limited to using only the binding customizations defined in the specification. By using the "-extension" switch, you will be allowed to use the JAXB Vendor Extensions.
> -b <file>
>   Specify one or more external binding files to process. (Each binding file must have it's own `"-b"` switch.) The syntax of the external binding files is extremely flexible. You may have a single binding file that contains customizations for multiple schemas or you can break the customizations into multiple bindings files:

>   > `xjc schema1.xsd schema2.xsd schema3.xsd -b bindings123.xjb
>   > xjc schema1.xsd schema2.xsd schema3.xsd -b bindings1.xjb -b bindings2.xjb -b bindings3.xjb`

>   In addition, the ordering of the schema files and binding files on the command line does not matter.
> -d <dir>
>   By default, the XJC binding compiler will generate the Java content classes in the current directory. Use this option to specify an alternate output directory. The output directory must already exist, the XJC binding compiler will not create it for you.
> -p <pkg>
>   Specifying a target package via this command-line option overrides any binding customization for package name and the default package name algorithm defined in the specification.
> -host <proxyHost>
>   Specify a value for the `http.proxyHost` networking property.
> -port <proxyPort>
>   Specify a value for the `http.proxyPort` networking property.
> -classpath <arg>
>   Specify where to find client application class files used by the `<jxb:javaType>` and `<xjc:superClass>` customizations.
> -catalog <file>
>   Specify catalog files to resolve external entity references. Supports TR9401, XCatalog, and OASIS XML Catalog format. Please read the XML Entity and URI Resolvers document or the `catalog-resolver` sample application.
> -readOnly
>   By default, the XJC binding compiler does not write-protect the Java source files it generates. Use this option to force the XJC binding compiler to mark the generated Java sources read-only.
> -use-runtime <pkg>
>   suppress the generation of the `impl.runtime` package and simply refer to another existing runtime in the specified package. This option is useful when you are compiling multiple independent schemas. Because the generated `impl.runtime` packages are identical except for their package declarations, you can reduce the size of your generated codebase by telling the compiler to reuse an existing `impl.runtime` package.

>   When using this switch, be careful to specify a version of the runtime package compatible with your version of JAXB. Otherwise, you may encounter javac failures when attempting to compile your generated classes. For example, you should not specify a set of runtime classes generated from an older version of the binding compiler with the current binding compiler.

> -xmlschema
>   treat input schemas as W3C XML Schema (default). If you do not specify this switch, your input schemas will be treated as W3C XML Schema.
> -relaxng
>   Treat input schemas as RELAX NG (experimental, unsupported). Support for RELAX NG schemas is provided as a JAXB Vendor Extension.
> -dtd
>   Treat input schemas as XML DTD (experimental, unsupported). Support for RELAX NG schemas is provided as a JAXB Vendor Extension.
> -quiet
>   Suppress compiler output, such as progress information and warnings..
> -help
>   Display a brief summary of the compiler switches.
> -version
>   Display the compiler version information.
> <schemas>
>   Specify one or more schema files to compile.

### Summary of Non-Standard Command Line Options

> -Xlocator
>   This feature is only available when you include jwsdp-N/A/jaxb/samples/locator-support/jaxb-locator-support.jar on your classpath. Please refer to the readme.txt file located with the sample app for more detail.
> -Xsync-methods
>   This feature is only available when you include jwsdp-N/A/jaxb/samples/synchronized-methods/jaxb-synchronized-methods.jar on your classpath. Please refer to the readme.txt file located with the sample app for more detail.

### Compiler Restrictions

In general, it is safest to compile all related schemas as a single unit with the same binding compiler switches.

Please keep the following list of restrictions in mind when running xjc. Most of these issues only apply when compiling multiple schemas with multiple invocations of xjc.

- To compile multiple schemas at the same time, keep the following precedence rules for the target Java package name in mind:
  1. The "`-p`" command line option takes the highest precedence.
  2. <`jaxb:package`> customization
  3. If `targetNamespace` is declared, apply `targetNamespace` -> Java package name algorithm defined in the specification.
  4. If no `targetNamespace` is declared, use a hardcoded package named "generated".
- It is not legal to have more than one <`jaxb:schemaBindings`> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages.
- All schemas being compiled into the same Java package must be submitted to the XJC binding compiler at the same time - they cannot be compiled independently and work as expected.
- Element substitution groups and type substitution definitions spread across multiple schema files must be compiled at the same time.
- When using the "-use-runtime" switch on the binding compiler, be careful to specify a version of the runtime package compatible with your version of JAXB. Otherwise, you may encounter javac failures when attempting to compile your generated classes. For example, you should not specify a set of runtime classes generated from an older version of the binding compiler (v1.0.1) with the current binding compiler (v1.0.2).

### Generated Resource Files

The xjc binding compiler produces a set of packages containing a combination of Java source files and resource files. The following list of resource files generated by xjc must be kept with the compiled source code and made available on the runtime classpath of your client applications:

> - jaxb.properties
> - bgm.ser

A pair of these resource files is contained in each of the packages containing schema-derived Java content interfaces. Make sure to copy these resource files into the appropriate directories to maintain the proper relationship with the generated Java source files. The following snippet of Ant code illustrates how this can be achieved:

>     <path id="classpath">
>     ...
>     </path>

>     <target name="compile">
>       <!-- compile all xsd files in the src dir and put the output in the build dir -->
>       <xjc target="build">
>         <schema  dir="src" includes="*.xsd"/>
>         <binding dir="src" includes="*.xjb"/>
>       </xjc>

>       <!-- compile all java files in the src dir and put the output in the build dir -->
>       <javac srcdir="src" destdir="build" debug="on">
>         <classpath refid="classpath" />
>       </javac>

>       <!-- copy all of the generated resource files from the src dir into the build dir -->
>       <copy toDir="build">
>         <fileset dir="src">
>           <include name="**/jaxb.properties"/>
>           <include name="**/bgm.ser"/>
>         </fileset>
>       </copy>
>     </target>

### Specifying Proxy Settings

The XJC binding compiler has support for the `http.proxyHost` and `http.proxyPort` networking properties. Specify the "`-host`" and "`-port` " command-line options on the `xjc` scripts that are located in the `bin` directory.

If you are launching the XJC binding compiler manually, you can specify the values of these properties on the Java command line as follows:

> For Solaris/Linux:
>   `% java -Dhttp.proxyHost=myproxy.com -Dhttp.proxyPort=80 -jar $JAXB_HOME/lib/jaxb-xjc.jar -help`
> For Windows:
>   `> java -Dhttp.proxyHost=myproxy.com -Dhttp.proxyPort=80 -jar %JAXB_HOME%\lib\jaxb-xjc.jar -help`

$Revision: 1.1 $
$Date: 2008/11/03 06:51:11 $