【问题标题】:Maven jaxb2:xjc failing to generate codeMaven jaxb2:xjc 无法生成代码
【发布时间】:2015-05-12 20:28:55
【问题描述】:

我在 pom.xml 中的 Maven 构建中添加了以下插件

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration> 
                <extension>true</extension>                             
                <clearOutputDir>false</clearOutputDir>
                <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
                <schemaFiles>myapp.xsd</schemaFiles>                                                        
                <outputDirectory>${basedir}/src/main/java</outputDirectory>         
                <bindingDirectory>src/main/resources/xsd</bindingDirectory>     
                <bindingFiles>myapp-bindings.xjb</bindingFiles>
            </configuration>
        </execution>
    </executions>                       

</plugin>

以下是构建错误。

[INFO] Ignored given or default xjbSources [C:\WorkSpace\MyApp\src\main\xjb], since it is not an existent file or directory.
[INFO] Ignored given or default sources [C:\WorkSpace\MyApp\src\main\xsd], since it is not an existent file or directory.
[WARNING] No XSD files found. Please check your plugin configuration.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.273s
[INFO] Finished at: Tue May 12 16:24:26 EDT 2015
[INFO] Final Memory: 9M/124M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "dev-artifactory" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc (default) on project pml-jasypt-authentication-service: MojoExecutionException: NoSchemasException -> [Help 1]

我一头雾水,为什么插件没有引用配置中指定的路径和文件。

【问题讨论】:

    标签: maven build jaxb xjc


    【解决方案1】:

    2.1 版更改了指定来源的方式

    http://mojo.codehaus.org/jaxb2-maven-plugin/xjc-mojo.html#sources

    例如

    <configuration>
    ...
      <sources>
         <source>some/explicit/relative/file.xsd</source>
         <source>/another/absolute/path/to/a/specification.xsd</source>
         <source>a/directory/holding/xsds</source>
     </sources>
    </configuration>
    

    我遇到了一大堆其他问题,所以按照 jshark 的建议坚持使用 1.6 是一个不错的计划

    【讨论】:

    • 该死的,到处都喜欢变化。我正在将一个系统从 JDK7 迁移到 JDK11,这是一整套让 XSD 正常工作的蠕虫。
    【解决方案2】:

    2.1 版存在错误。

    您可以将&lt;version&gt;2.2&lt;/version&gt; 与新语法一起使用:

    <configuration>
    ...
      <sources>
         <source>some/explicit/relative/file.xsd</source>
         <source>/another/absolute/path/to/a/specification.xsd</source>
         <source>a/directory/holding/xsds</source>
     </sources>
    </configuration>
    

    您可以将&lt;version&gt;1.6&lt;/version&gt; 与旧语法一起使用:

    <configuration>
        ...
        <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
        <schemaFiles>myapp.xsd</schemaFiles> 
    </configuration>
    

    【讨论】:

      【解决方案3】:

      我今天遇到了同样的问题,并通过以下方式解决了:

      <version>1.6</version>
      

      关于插件定义(这通常是很好的做法)

      【讨论】:

        【解决方案4】:

        我通过将编译器版本设置为JDK 1.8 和jaxb2-maven-plugin 版本1.5 使其工作 根据documention 的说法,它适用于最低 JDK 1.6 [如果在站点中更改链接可能会失效]。例如:

        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.mntq.jaxb.xsd.to.pojo</groupId>
          <artifactId>XsdToPojo</artifactId>
          <version>0.0.1-SNAPSHOT</version>
        
        
          <build>
                <finalName>PersistencePoJO</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                     <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>1.5</version>
                    <executions>
                        <execution>
                            <id>xjc</id>
                            <goals>
                                <goal>xjc</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <!-- The package of your generated sources -->
                        <packageName>com.mntq.jaxb.pojo</packageName>
                    </configuration>
                </plugin>
                </plugins>
            </build>
        </project> 
        

        【讨论】:

          【解决方案5】:

          我们也可以这样使用:

                     <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>jaxb2-maven-plugin</artifactId>
                      <version>1.5</version>
                      <executions>
                          <execution>
                              <id>id1</id>
                              <goals>
                                  <goal>xjc</goal>
                              </goals>
                              <configuration>
                                  <outputDirectory>src/main/java</outputDirectory>
                                  <clearOutputDir>false</clearOutputDir>
                                  <packageName>com.subu.xsd.model</packageName>
                                  <schemaDirectory>src/main/java/schemadir</schemaDirectory>
                                  <schemaFiles>XYZ.xsd</schemaFiles>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
          

          【讨论】:

            【解决方案6】:

            我通过检查 eclipse maven 更新中的“强制更新快照/发布”选项解决了这个问题。

            它强制它更新所有相关的依赖项。

            【讨论】:

              【解决方案7】:

              如果您只是将 xerces 依赖项添加到 jaxb 插件声明的末尾,它将有效。这很简单:插件只需要一些类来执行。现在给他:) 一、塞纳托夫。

                          <plugin>
                          <groupId>org.codehaus.mojo</groupId>
                          <artifactId>jaxb2-maven-plugin</artifactId>
                          <version>1.6</version>
                          <executions>
                              <execution>
                                  <phase>generate-sources</phase>
                                  <id>xjc-dtd</id>
                                  <goals>
                                      <goal>xjc</goal>
                                  </goals>
                                  <configuration>
                                      <arguments>-dtd</arguments>
                                      <dtd>true</dtd>
                                      <!-- The package of your generated sources -->
                                      <packageName>mi.minet.lurc.dtd</packageName>
                                      <schemaDirectory>src/main/resources/dtd</schemaDirectory>
                                      <schemaFiles>lurc.dtd</schemaFiles>
                                  </configuration>
                              </execution>
                              <execution>
                                  <phase>generate-sources</phase>
                                  <id>xjc-xsd</id>
                                  <goals>
                                      <goal>xjc</goal>
                                  </goals>
                                  <configuration>
                                      <packageName>mi.minet.lurc.xsd.configuration</packageName>
                                      <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                                      <schemaFiles>configuration.xsd</schemaFiles>
                                      <clearOutputDir>false</clearOutputDir>
                                  </configuration>
                              </execution>
                          </executions>
                          <dependencies>
                              <dependency>
                                  <groupId>xerces</groupId>
                                  <artifactId>xercesImpl</artifactId>
                                  <version>2.11.0</version>
                              </dependency>
                          </dependencies>
                      </plugin>
              

              【讨论】:

              • 不,不需要,因为 jaxb2-maven-plugin 不依赖 xerces 工作。我只是试了一下,不管有没有你的小费,它甚至都没有加载。我不明白,为什么你把你的 pom sn-p 放在这里。您是否阅读了 OP 中的异常?这里的问题是,由于缺少一些库,没有找到 Schema,而不是编译错误。
              【解决方案8】:

              就我而言,我通过将我的 jdk 编译器版本从 jdk 10 降级到 jdk 1.8 来让它工作

              【讨论】:

                【解决方案9】:

                在某些情况下,例如,您应该在构建之前使用mvn clean

                mvn clean compile
                

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2015-01-12
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2012-03-31
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多