Running JaxMe Schema Generator / Compiler from the Command Line

JaxMe is an open source implementation of the Java API for XML Binding (JAX-B). Running JaxMe schema generator (Sun calls the equivalent piece of software in its own JAX-B implementation the schema compiler) is normally part of your build process and there’s is a sample ANT task on the website. If you happen to build your project with Maven, there is a maven-plugin, too.

But just without ANT or Maven, running JaxMe from the command line needs the following:

  1. Unpack the JaxMe distribution into a directory (here: d:\prg\jaxme-051)
  2. Write yourself a shell script like this one:
    set JAXMELIB=D:\prg\jaxme-051\lib
    java -cp %JAXMELIB%\jaxme2-0.5.1.jar;%JAXMELIB%\jaxmeapi-0.5.1.jar;%JAXMELIB%\jaxmejs-0.5.1.jar;%JAXMELIB%\jaxmexs-0.5.1.jar org.apache.ws.jaxme.generator.Main %*
  3. Save this as xjc.cmd (that’s what Sun called their stuff)
  4. Running xjc should give you the JaxMe command line options, like:
    A Schema file must be specified
    
    Usage: org.apache.ws.jaxme.generator.Main  [options]
    
    Reads a schema definition from the given 
    Possible options are:
      --bindingFile= Adds an external binding file.
                               Multiple external binding files may
                               be used by repeating this option.
      --force                  Force overwriting files
      --schemaReader=   Sets the SchemaReader class; defaults to
                               org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader
      --sgFactoryChain= Adds an instance of  to the
                               generation process.
      --logFile=     Sets a logfile for debugging purposes.
                               By default System.err is used.
      --logLevel=       Sets the default logging level.
                               Possible levels are fatal, error (default),
                               warn, info and debug
      --option=    Sets the option  to the given .
      --package=         Sets the package of the generated sources to
                               .
      --resourceTarget=   Sets the directory where to generate
                               resource files. By default, the same directory
                               is used for Java sources and resource files.
      --target=           Sets the directory where to generate Java
                               sources. By default the current directory
                               is used.
      --validating             Turns the XML parsers validation on.
    
  5. Write another shell script for transforming a schema (I do this because I hate to loose a hard-fought-for command line to an accidental exit in the wrong shell. Additionally I can’t always remember all them incantations when I need to run the same stuff days later.) You need to specify the schema, the target package and the target directory, in which the package will be created (this would be some path pointing into your project). Like so:
    xjc --target d:\src\Verifications\src\jaxme --package de.inpc.[something].vo D:\src\Verifications\src\jaxme\[something].xsd

    Call it compile-[something].cmd

  6. Running the compile-[something] shell script should generate lots of logging and output java classes generated from the schema in your target directory.
  7. These are java sources, before using them you need to compile them.

That’s all it takes – happy JaxMe-ing!

 

Andreas