java .xsd 不是此编译的一部分。这是 .xjb 的错误吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33232039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.xsd is not a part of this compilation. Is this a mistake for .xjb
提问by onknows
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.
我试图schemaLocation
在我的xjb
文件中更改为不使用使用 URL 的远程文件,而是使用同样受版本控制的本地副本。
So for example my xjb
file has something similar to
所以例如我的xjb
文件有类似的东西
<?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
mvn clean install
将失败并显示类似于
[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"?
[警告] 引起:com.sun.istack.SAXParseException2; systemId: 文件:/E:/somefolder/somefolder/myjavaproject/target/bindings/myxjb.xjb; 行号:33;列数:33;“file:/E:/somefolder/somefolder/myjavaproject/target/bindings/mywsdl.wsdl”不是这个编译的一部分。这是“文件:/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.
我注意到它正在目录中寻找我的 wsdl 文件target
。我可以schemaLocation
以指向src
目录的方式操作 。然后路径存在,但消息仍然存在。
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.
我也可以将 wsdl 放在目标目录中,java 尝试在其中找到它,但在这种情况下,消息也保持不变。
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?
所以看起来需要发生一些特定的事情才能使它成为这个编译的一部分。应该怎么做才能以正确的方式编译它?
采纳答案by Macilias
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"
在我的环境(2.2 版)中,它仅在文件位于专用文件夹(src/main/xsd/schema.xsd 中的架构和 binding ind src/main/xsb/binding.xsb)中时才有效,并且绑定文件相对引用了架构:schemaLocation="../xsd/schema.xsd"
It really seams to be fragile.
它真的很脆弱。
回答by Kirill Ch
It starts working after I add my xsd in pom-file in configuration of a plugin, like this:
在插件配置中将我的 xsd 添加到 pom-file 后,它开始工作,如下所示:
<bindingDirectory>
src/main/resources/binding
</bindingDirectory>
<bindingFiles>
<bindingFile>bindings.xjb</bindingFile>
<bindingFile>../xsd/egrul.xsd</bindingFile>
<bindingFile>../xsd/arrays.xsd</bindingFile>
</bindingFiles>
回答by Vivek Shukla
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:
首先,假设您正在使用一些插件来生成存根。我使用 cxf-codegen-plugin(你可以使用任何),重要的一步是定义你的绑定文件的位置,假设它在一个 resources\wsdl 里面,
这是代码片段:
<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
接下来,现在在执行“mvn generate-sources”时,maven 知道在哪里查找绑定文件。假设您还将 xsd 文件放在 resources\wsdl 文件夹中(您可以有任何路径)
让我们看看 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.
由于您已经在 maven 插件中定义了绑定文件路径,并且您的 xsd 也在该路径中,因此您无需在绑定文件的 schemaLocation 中再次定义此路径。
回答by Rob
I have had success with
我已经成功
Put both the schema and bindings in src/main/resources
src/main/resources/myxsd.xsd
src/main/resources/mybindings.xjb
Point your maven plugin that is going to run xjc to find the files there
In the bindings file use
schemaLocation="myxsd.xsd"
将架构和绑定都放在 src/main/resources 中
src/main/resources/myxsd.xsd
src/main/resources/mybindings.xjb
指向将运行 xjc 以在那里查找文件的 Maven 插件
在绑定文件中使用
schemaLocation="myxsd.xsd"
If you want to add some directories under src/main/resources, you can certainly do that - you will have to figure out the proper relative path to use when specifying schemaLocation.
如果您想在 src/main/resources 下添加一些目录,您当然可以这样做 - 您必须在指定 schemaLocation 时找出要使用的正确相对路径。
回答by Joshua Goldberg
I received this error during compilation because my IDE had added a bin/
directory under the package with the JAXB compilation. It was fixed by either using rm -rf BaseDirectory/bin/
or rm -rf BaseDirectory; git co BaseDirectory
. The latter is probably better/more complete.
我在编译期间收到此错误,因为我的 IDE 在bin/
带有 JAXB 编译的包下添加了一个目录。它是通过使用rm -rf BaseDirectory/bin/
或修复的rm -rf BaseDirectory; git co BaseDirectory
。后者可能更好/更完整。
(Eclipse, which I use rarely, compiles outputs into bin/
, whereas IntelliJ IDEA or raw gradle compiles into build/
)
(Eclipse,我很少使用,将输出编译为bin/
,而 IntelliJ IDEA 或原始 gradle 编译为build/
)
回答by Vitaly Sazanovich
In my case I just had to update maven-jaxb2-plugin version:
就我而言,我只需要更新 maven-jaxb2-plugin 版本:
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>