Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SMILA/Development Guidelines/Setup for JAXB code generation"

(Generate Sources from Command line)
Line 48: Line 48:
 
}}
 
}}
  
 +
{{note| Setup alternative with JDK 1.6 |
 +
 +
[http://giorgiosironi.blogspot.com Giorgio Sironi] pointed us to a possibility to get the JAXB generation running with JDK 1.6:
 +
 +
* Download the "Distribution" from [http://confluence.highsource.org/display/J2B/Home]
 +
* From the ZIP, copy <tt>jaxb2-basics-dist-0.5.2/dist/jaxb2-basics-ant-0.5.2.jar</tt> to <tt><SMILA-Build-Lib-Dir>/xjc</tt>.
 +
* in <tt>SMILA.builder/xjc/build.xml</tt> edit the task definition for <tt>xjc</tt>:
 +
<source lang="text">
 +
  <!-- original version: <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">, replace with: -->
 +
  <taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
 +
</source>
 +
 +
Now the above instructions should work using a JDK 1.6, too. Thanks, Giorgio!
 +
}}
  
 
=== Generating  JAXB classes for a new crawler or agent configuration ===
 
=== Generating  JAXB classes for a new crawler or agent configuration ===

Revision as of 09:38, 27 April 2010

Introduction

This page describes additional setup steps you need to do if you want to use JAXB to generate classes from XML schema descriptions for SMILA. This is also needed to be able to extend SMILA XML configuration file schemas, because we mostly use JAXB to parse them.


Steps to install needed libraries

  1. Setup a build library as described in SMILA/Development Guidelines/Howto build a SMILA-Distribution. In this document we will use lib/ as the root of it.
  2. Download the JAXB reference implementation 2.1.6 or above from here
  3. unpack it with (see here)
    java -jar <JAXB-version>.jar
  4. copy the following into your lib/xjc
    • all jars in the jaxb-ri-<version>/lib/
    • InterfacesXJCPlugin.jar that you can get here

Your build lib directory should now look at least like this:

lib/
   ant-contrib/
      ant-contrib-1.0b1.jar
   xjc/
      jaxb-xjc.jar
      InterfacesXJCPlugin.jar
      activation.jar
      jaxb-api.jar
      jaxb-impl.jar
      jsr173_1.0_api.jar

Generate Sources from Command line

  1. Put SMILA.builder into the same folder as the bundle for which you are generating the folder (for all SMILA bundles this is the case after a checkout).
  2. To generate the classes, you can now use:
    ant -Dlib.dir=<SMILA-Build-Lib-Dir>

The JAXB classes should now be generated in the code/gen directory of your bundle.

Note.png
JDK 1.5 needed
This setup works correctly only when using a JDK 1.5 to run ant. With JDK 1.6 you'll get a message like this:
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: 
Provider com.w_wins.xml.xjcplugins.InterfacePlugin could not be instantiated: 
java.lang.ClassCastException
We are looking for a version of this plugin that works with JDK 1.6, too. Any hints are welcome.


Note.png
Setup alternative with JDK 1.6
Giorgio Sironi pointed us to a possibility to get the JAXB generation running with JDK 1.6:
  • Download the "Distribution" from [1]
  • From the ZIP, copy jaxb2-basics-dist-0.5.2/dist/jaxb2-basics-ant-0.5.2.jar to <SMILA-Build-Lib-Dir>/xjc.
  • in SMILA.builder/xjc/build.xml edit the task definition for xjc:
  <!-- original version: <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">, replace with: -->
  <taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
Now the above instructions should work using a JDK 1.6, too. Thanks, Giorgio!


Generating JAXB classes for a new crawler or agent configuration

  1. If you do not yet have a binary distribution of SMILA: Download or build one.
  2. Copy org.eclipse.smila.connectivity.framework.schema_0.5.0.jar from the plugins directory of the SMILA distribution to lib/xjc. This is necessary because crawler configurations extend a base schema and therefore need to access classes in this bundle.
  3. Put your bundle next to the SMILA.builder source bundle.
  4. Add a code/gen folder to your bundle and add it as a source folder.
  5. Create a schemas directory in your bundle and put the XSD and JXB file there (use the same basename and xsd and jxb as suffixes).
  6. Create a build.xml in the bundle directory with this content, replace $SCHEMA_NAME with the basename of the XSD/JXB files:
 <project name="sub-build" default="compile-schema-and-decorate" basedir=".">
  <property name="schema.name" value="$SCHEMA_NAME" />
  <import file="../SMILA.builder/xjc/build.xml" />
 </project>

You can optionally add a file copyright.txt to the bundle (next to build.xml) containing a copyright header for the generated files (use valid Java comment syntax).

Back to the top