Jump to: navigation, search

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

(refactored this page and trimmed it)
Line 1: Line 1:
 +
=== 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.  
 
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.  
  
'''NOTE''' This setup works correctly only when using a JDK 1.5 to run <tt>ant</tt>. With JDK 1.6 you'll get a message like this:
 
  
<source lang="text">
+
=== Steps to install needed libraries ===
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin:
+
Provider com.w_wins.xml.xjcplugins.InterfacePlugin could not be instantiated:
+
java.lang.ClassCastException
+
</source>
+
 
+
We are looking for a version of this plugin that works with JDK 1.6, too. Any hints are welcome.
+
  
* Setup a build libraries as described in [[SMILA/Development Guidelines/Howto build a SMILA-Distribution]].
+
# Setup a build library as described in [[SMILA/Development Guidelines/Howto build a SMILA-Distribution]]. In this document we will use {{path|lib/}} as the root of it.
* Download the JAXB reference implementation 2.1.6 from [https://jaxb.dev.java.net/2.1.6/ https://jaxb.dev.java.net/2.1.6/], unpack it as described and copy <tt>jaxb-ri-20071219/lib/jaxb-xjc.jar</tt> to <tt>lib/xjc</tt> in the directory containing the additional libraries for building you created in the first step. Download <tt>InterfacesXJCPlugin.jar</tt> from [http://xml.w-wins.com/xjc-plugins/interfaces/ http://xml.w-wins.com/xjc-plugins/interfaces/] and add it to the lib/xjc directory, too. Your build lib directory should now look at least like this:
+
# Download the JAXB reference implementation 2.1.6 or above from [https://jaxb.dev.java.net/servlets/ProjectDocumentList here]
 +
# unpack it with (see [https://jaxb.dev.java.net/2.1.6/ here]) <source lang="text">java -jar <JAXB-version>.jar </source>
 +
# copy the following into your <tt>lib/xjc</tt>  
 +
#* all jars in the {{path|jaxb-ri-<version>/lib/}}
 +
#* <tt>InterfacesXJCPlugin.jar</tt> that you can get [http://xml.w-wins.com/xjc-plugins/interfaces here]  
 +
Your build lib directory should now look at least like this:
 
<source lang="text">
 
<source lang="text">
 
lib/
 
lib/
Line 20: Line 20:
 
       jaxb-xjc.jar
 
       jaxb-xjc.jar
 
       InterfacesXJCPlugin.jar
 
       InterfacesXJCPlugin.jar
</source>
 
* If you are developing with an [[SMILA/Development Guidelines/How to set up integration environment|integration environment]]:
 
** From <tt>jaxb-ri-20071219/lib/</tt> copy also these jars to <tt>lib/xjc</tt>:
 
<source lang="text">
 
lib/
 
  xjc/
 
      ...
 
 
       activation.jar
 
       activation.jar
 
       jaxb-api.jar
 
       jaxb-api.jar
Line 32: Line 25:
 
       jsr173_1.0_api.jar       
 
       jsr173_1.0_api.jar       
 
</source>
 
</source>
** You need to checkout at least the bundle <tt>SMILA.builder</tt> from the SMILA subversion repository [http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/ http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/] into your workspace. Choose the version from the tag matching the SMILA version you want to develop for or use trunk.
+
 
** In file <tt>SMILA.builder/xjc/build.xml</tt> remove these lines from the path definition <tt>xjc.classpath</tt>:
+
=== Generate Sources  from Command line ===
<source lang="xml">
+
 
<fileset dir="../SMILA.extension/eclipse/plugins/" includes="javax.activation*.jar" />
+
#  Put <tt>[http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/SMILA.builder SMILA.builder]</tt> 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).    
<fileset dir="../javax.xml.bind" includes="*.jar" />
+
#  To generate the classes, you can now use:<source lang="text">
<fileset dir="../javax.xml.stream" includes="*.jar" />
+
ant -Dlib.dir=<SMILA-Build-Lib-Dir>
<fileset dir="../com.sun.jaxb" includes="*.jar" />
+
 
</source>
 
</source>
* If you want to generate JAXB classes for a new crawler configuration:
 
** If you do not yet have a binary distribution of SMILA: [http://www.eclipse.org/smila/downloads.php Download] or build one.
 
** Copy <tt>org.eclipse.smila.connectivity.framework.schema_0.5.0.jar</tt> from the plugins directory of the SMILA distribution to <tt>lib/xjc</tt>. This is necessary because crawler configurations extend a base schema and therefore need to access classes in this bundle.
 
* Put your bundle next to the <tt>SMILA.builder</tt> source bundle.
 
* Create a <tt>schemas</tt> directory in your bundle and put the XSD and JXB file there (use the same basename and <tt>xsd</tt> and <tt>jxb</tt> as suffixes).
 
* Create a <tt>build.xml</tt> in the bundle directory with this content, replace $SCHEMA_NAME with the basename of the XSD/JXB files:
 
  
<source lang="xml">
+
The JAXB classes should now be generated in the <tt>code/gen</tt> directory of your bundle.
<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>
+
</source>
+
  
* You can optionally add a file <tt>copyright.txt</tt> to the bundle (next to build.xml) containing a copyright header for the generated files (use valid Java comment syntax).
+
{{note| JDK 1.5 needed |
* Add a <tt>code/gen</tt> folder to your bundle and add it as a source folder.
+
  
To generate the classes, you can now use:
+
This setup works correctly only when using a JDK 1.5 to run <tt>ant</tt>. With JDK 1.6 you'll get a message like this:
  
 
<source lang="text">
 
<source lang="text">
ant -Dlib.dir=<SMILA-Build-Lib-Dir>
+
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin:
 +
Provider com.w_wins.xml.xjcplugins.InterfacePlugin could not be instantiated:
 +
java.lang.ClassCastException
 
</source>
 
</source>
  
If you have created the folder with the build libs in the same directory where <tt>SMILA.builder</tt> is locaoted, you can just use:
+
We are looking for a version of this plugin that works with JDK 1.6, too. Any hints are welcome.
 +
}}
  
<source lang="text">
 
ant
 
</source>
 
  
The JAXB classes should now be generated in the <tt>code/gen</tt> directory of your bundle.
+
=== Generating  JAXB classes for a new crawler configuration ===
 +
#  If you do not yet have a binary distribution of SMILA: [http://www.eclipse.org/smila/downloads.php Download] or build one.
 +
# Copy <tt>org.eclipse.smila.connectivity.framework.schema_0.5.0.jar</tt> from the plugins directory of the SMILA distribution to <tt>lib/xjc</tt>. This is necessary because crawler configurations extend a base schema and therefore need to access classes in this bundle.
 +
# Put your bundle next to the <tt>SMILA.builder</tt> source bundle.
 +
# Add a <tt>code/gen</tt> folder to your bundle and add it as a source folder.
 +
# Create a <tt>schemas</tt> directory in your bundle and put the XSD and JXB file there (use the same basename and <tt>xsd</tt> and <tt>jxb</tt> as suffixes).
 +
# Create a <tt>build.xml</tt> in the bundle directory with this content, replace $SCHEMA_NAME with the basename of the XSD/JXB files:
 +
 
 +
<source lang="xml">
 +
<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>
 +
</source>
 +
 
 +
You can optionally add a file <tt>copyright.txt</tt> to the bundle (next to build.xml) containing a copyright header for the generated files (use valid Java comment syntax).
 +
 
  
 
[[Category:SMILA]]
 
[[Category:SMILA]]

Revision as of 07:40, 6 November 2009

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.


Generating JAXB classes for a new crawler 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).