I am using WsImport
to generate some Java sources from a remote WSDL file. Note that this is being from inside a regular Scala project i.e. it is not being done in a Maven or Ant build:
import com.sun.tools.ws.WsImport
def run(wsdlFile: File, destination: File, packageName: String = "generated"): Seq[File] = {
sys.props("javax.xml.accessExternalDTD") = "all"
sys.props("javax.xml.accessExternalSchema") = "all"
val xjcArgs = "" //TODO
val args = s"-Xnocompile -XadditionalHeaders $xjcArgs -J-Djavax.xml.accessExternalDTD=all -b http://www.w3.org/2001/XMLSchema.xsd -p $packageName -s $destination $wsdlFile"
WsImport.doMain(args.split(' '))
}
The above code works great and I use it to generate a Java WSDL client programatically from above Scala code.
But, now, I also want to use some WsImport plugins (such as this and this):
val xjcArgs = "-B-Xequals -B-XhashCode -B-Xvalue-constructor"
I am getting this error: no such JAXB option: -Xequals
even though I added the following to my classpath:
"org.jvnet.jaxb2_commons" % "jaxb2-basics" % "1.11.1",
"org.jvnet.jaxb2_commons" % "jaxb2-value-constructor" % "3.0",
How do I force WsImport to use these plugins? Or do I use some other tool besides the WsImport (such as ANT) directly?
Trying with ANT
I am using com.sun.tools.ws.WsImport
above but there is also another com.sun.tools.ws.ant.WsImport
and I am not compeltely sure how to use it. I tried this:
val task = new com.sun.tools.ws.ant.WsImport2()
task.setPackage(packageName)
task.setWsdl(wsdlFile.getAbsolutePath)
task.setDestdir(destination.getAbsoluteFile)
task.setGenerateJWS(true)
task.setXadditionalHeaders(true)
task.setXnocompile(true)
task.setBinding("http://www.w3.org/2001/XMLSchema.xsd")
task.execute()
The above "almost works" but I can't figure out how to set binding in the ant task. wsimport
takes in a -b http://www.w3.org/2001/XMLSchema.xsd
but the ant task only accepts files as arguments :(
wsimport -cp ~/.ivy2/cache/org.jvnet.jaxb2_commons/jaxb2-basics/jars/jaxb2-basics-1.11.1.jar -B-Xequals -B-XhashCode -B-XtoString -B-Xcopyable -B-Xsetters -B-Xvalue-constructor -Xnocompile -XadditionalHeaders -J-Djavax.xml.accessExternalDTD=all -b http://www.w3.org/2001/XMLSchema.xsd -p com.company.foo.wsdl -s generated_sources /path/to/file.wsdl
?? I get same error from command line OR scala ... – Ebenezer