This discussion is archived
0 Replies Latest reply: Nov 27, 2012 5:54 PM by jmsjr RSS

wsimport, mapping of xs:date to java.util.Date via ext file, and -B option

jmsjr Newbie
Currently Being Moderated

JDK 1.7.0_09 and wsimport and xjc that comes with it.
Global JAXB binding to map xs:date to java.util.Date

I have the following external bindings file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=""
     xmlns:jaxb="" xmlns:xjc=""
     elementFormDefault="qualified" attributeFormDefault="unqualified"
     jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
                    <xjc:serializable />
                    <jaxb:javaType name="java.util.Date" xmlType="xs:date" parseMethod="" printMethod="" />
The code is as follows:

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.bind.DatatypeConverter;

public class DateAdapter {
     public static Date parseDate(String s) {
          return DatatypeConverter.parseDate(s).getTime();
     public static String printDate(Date dt) {
          Calendar cal = new GregorianCalendar();
          return DatatypeConverter.printDate(cal);
When I run the following wsimport from the command line, I get:
salvojo@AUD20901BL /cygdrive/c/workspace/JSF/insurance
$ /cygdrive/c/java/jdk1.7.0_09/x64/bin/wsimport -keep -s gen-src -b external/wsdl/jaxb-bindings.xml -wsdllocation /wsdl/Member.wsdl -d WebContent/WEB-INF/classes external/wsdl/Member.wsdl
parsing WSDL...

Generating code...

Compiling code...

C:\workspace\JSF\insurance\gen-src\org\w3\_2001\xmlschema\ error: package does not exist
        return (;
C:\workspace\JSF\insurance\gen-src\org\w3\_2001\xmlschema\ error: package does not exist
        return (;
2 errors
compilation failed, errors should have been reported
Which means that wsimport or xjc needs to know the classpath to find
But how do I pass the classpath from wsimport to the JAXB compiler ?

There is the -B option in wsimport, but I could not get it to work.
If I read it correctly, I should be able to pass the -classpath option to the JAXB compiler from wsimport via -B.
I tried:
salvojo@AUD20901BL /cygdrive/c/workspace/JSF/insurance
$ /cygdrive/c/java/jdk1.7.0_09/x64/bin/wsimport -keep -s gen-src -B"-classpath WebContent/WEB-INF/classes" -b external/wsdl/jaxb-bindings.xml -wsdllocation /wsdl/Member.wsdl -d WebContent/WEB-INF/classes external/wsdl/Member.wsdl
no such JAXB option: -classpath WebContent/WEB-INF/classes

Usage: wsimport [options] <WSDL_URI>

where [options] include:
  -b <path>                 specify jaxws/jaxb binding files or additional schemas
                            (Each <path> must have its own -b)
  -B<jaxbOption>            Pass this option to JAXB schema compiler
  -catalog <file>           specify catalog file to resolve external entity references
                            supports TR9401, XCatalog, and OASIS XML Catalog format.
  -d <directory>            specify where to place generated output files

... where WebContent/WEB-INF/classes is the classpath where could be found. Obviously it did not like it.

Also, why is wsimport generate ? All it is doing is wrapping up the exact same call that I have specified in my DateAdapter. How can I tell wsimport or xjc to NOT create that extra and simply directly use my DateAdapter ??


  • Correct Answers - 10 points
  • Helpful Answers - 5 points