I am trying to change schemaLocation
in my xjb
file to use not a remote file using URL but to use a local copy that is also under version control.
So for example my xjb
file has something similar to
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsd:ID="JaxbBindingsForWMiddleware"
version="2.0">
<jxb:bindings node="/xsd:schema"
schemaLocation="http://myserver:80/a/b/c/d/myxsd.xsd">
When I change this to local copy for example
schemaLocation="../../src/main/resources/myxsd.xsd">
mvn clean install
will fail with a message similar to
[WARNING] Caused by: com.sun.istack.SAXParseException2; systemId: file:/E:/somefolder/somefolder/myjavaproject/target/bindings/myxjb.xjb; lineNumber: 33; columnNumber: 33; "file:/E:/somefolder/somefolder/myjavaproject/target/bindings/mywsdl.wsdl" is not a part of this compilation. Is this a mistake for "file:/E:/somefolder/somefolder/myjavaproject/target/bindings/myxjb.xjb"?
I noticed that it is looking for my wsdl file in the target
directory. I can manipulate the schemaLocation
in such way that it points to the src
directory. The path then exists but the message remains.
I can also put the wsdl in the target directory, where java tries to find it but in that case also, the message stays the same.
So it looks like something specific needs to happen to make it part of this compilation. What should be done to compile this in the correct way?
It starts working after I add my xsd in pom-file in configuration of a plugin, like this:
<bindingDirectory>
src/main/resources/binding
</bindingDirectory>
<bindingFiles>
<bindingFile>bindings.xjb</bindingFile>
<bindingFile>../xsd/egrul.xsd</bindingFile>
<bindingFile>../xsd/arrays.xsd</bindingFile>
</bindingFiles>
In my environment (version 2.2) it only worked when the files was in dedicated folders (schema in src/main/xsd/schema.xsd and binding ind src/main/xsb/binding.xsb) and the binding file referenced the schema relatively: schemaLocation="../xsd/schema.xsd"
It really seams to be fragile.
While looking at problem, I can suggest below steps:
First, assuming you are using some plugin to generate your stubs. I use cxf-codegen-plugin( you can use any), important step is to define the location of your binding file, let's say its inside a resources\wsdl
Here is the snippet:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/YOUR_WSDL_NAME.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/YOUR_WSDL_NAME.wsdl</wsdlLocation>
<extraargs>
<extraarg>-xjc-Xts</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</plugin>
Next, so now while executing "mvn generate-sources", maven have idea where to look for your binding file. Let's assume that you are also putting your xsd file in resources\wsdl folder (you can have any path)
Let's see the snippet of binding.xml
<jxb:bindings schemaLocation="YOUR_XSD_FILE.xsd" node="/xs:schema">
.....
</jxb:bindings>
Since you have already defined your binding file path in maven plugin, and your xsd are also in that path, you needn't to define this path again in schemaLocation of your binding file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With