I'm trying to generate a client code with wsimport ant task with a special binding that converts "xs:dateTime" into
java.util.Date instead of the default XMLGregorianCalendar.
I'm following the example provided here: [Using different datatypes|https://jaxb.dev.java.net/guide/Using_different_datatypes.html]
Following the example I've created the class DateAdapter under the package foo(I'm just trying out things, it's not for production obviously :-) )
package foo;
import javax.xml.*;
import javax.xml.bind.*;
import java.util.*;
public class DateAdapter {
public static Date parseDate(String s) {
return DatatypeConverter.parseDate(s).getTime();
}
public static String printDate(Date dt) {
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
return DatatypeConverter.printDate(cal);
}
}
and jar it into classes.jar:
D:\Temp>jar -tvf classes.jar
0 Sat Apr 05 19:48:40 IDT 2008 META-INF/
71 Sat Apr 05 19:48:40 IDT 2008 META-INF/MANIFEST.MF
383 Sat Apr 05 19:48:04 IDT 2008 foo/DateAdapter.java
701 Sat Apr 05 19:48:10 IDT 2008 foo/DateAdapter.class
I've also created a special binding file my_bind.xml:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<javaType name="java.util.Date" xmlType="xs:dateTime"
parseMethod="foo.DateAdapter.parseDate"
printMethod="foo.DateAdapter.printDate"
/>
</globalBindings>
</bindings>
and finally my ant build file:
<project name="Bozaglo" default="create-client" basedir=".">
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"/>
<property name="src" value="src"/>
<property name="client" value="client"/>
<target name="create-client">
<mkdir dir="${client}"/>
<wsimport wsdl="http://localhost:8080/Phonebook2/PhoneEntryFetcher?wsdl" destdir="${client}" binding="my_bind.xjb">
<xjcarg value="-classpath"/>
<xjcarg value="classes.jar"/>
</wsimport>
<jar jarfile="${client}.jar" basedir="${client}"/>
</target>
<target name="clean">
<delete dir="${client}"/>
</target>
</project>
Notice that I pass classes.jar as xjc JAXB argument.
however when I run the ant build file I get the following error:
D:\Temp>ant
Buildfile: build.xml
create-client:
[mkdir] Created dir: D:\Temp\client
[wsimport] Consider using <depends>/<produces> so that wsimport won't do unnecessary compilation
[wsimport] parsing WSDL...
[wsimport]
[wsimport]
[wsimport] generating code...
[wsimport]
[wsimport]
[wsimport] compiling code...
[wsimport]
[wsimport] D:\Temp\client\org\w3\_2001\xmlschema\Adapter1.java:13: package foo does not exist
[wsimport] return (foo.DateAdapter.parseDate(value));
[wsimport] ^
[wsimport] D:\Temp\client\org\w3\_2001\xmlschema\Adapter1.java:17: package foo does not exist
[wsimport] return (foo.DateAdapter.printDate(value));
[wsimport] ^
[wsimport] 2 errors
[wsimport] compilation failed, errors should have been reported
[wsimport] Command invoked: wsimport "C:\Program Files\Java\jdk1.6.0_05\jre\bin\java.exe" -d D:\Temp\client http://localhos
t:8080/Phonebook2/PhoneEntryFetcher?wsdl -B-classpath classes.jar -b D:\Temp\my_bind.xjb
BUILD FAILED
D:\Temp\build.xml:11: wsimport failed
As you can see it doesn't find package foo, however if I specify the wsimport ant task not to compile
the files by using the xnocompile="true" attribute and then compile it myself it all works properly.
It seems to me that wsimport doesn't find classes.jar in the classpath, why does it happen and how do I fix
it?
Thanks :)
PS
I'm using jdk1.6.0_05 and JAX-WS RI 2.1.3 and ant-1.7.0
Edited by: Guest1234 on Apr 5, 2008 11:01 AM
Edited by: Guest1234 on Apr 5, 2008 11:03 AM