jsonix模式编译器Maven用法



我尝试根据https://github.com/highsource/jsonix-schema-compiler/wiki/Maven-Usage但不起作用

我甚至试图指定其他参数如下:

<build>
   <finalName>test-json</finalName>
   <plugins>
     <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xjsonix</arg>
                        <arg>-generateJsonSchema</arg>                          
                        <arg>-d</arg>
                        <arg>${basedir}/target/generated-sources/</arg>                         
                        <arg>-b</arg>
                        <arg>${basedir}/src/main/resources/xsd/jaxb_bindings.xjb</arg>                  
                        <arg>-p</arg>
                        <arg>CustomerJSON</arg>
                        <arg>-Xjsonix-logLevel</arg>
                        <arg>TRACE</arg>
                        <arg>${basedir}/src/main/resources/xsd/Customer.xsd</arg>
                    </args>
                    <plugins>
                        <plugin>
                            <groupId>org.hisrc.jsonix</groupId>
                            <artifactId>jsonix-schema-compiler</artifactId>
                            <version>${jsonix-schema-compiler.version}</version>
                        </plugin>
                    </plugins>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

但什么都没有改变,我得到的只是[警告]没有要编译的架构。正在跳过XJC执行。如以下日志所示

    C:test-json>mvn clean install  -Dmaven.test.skip=true
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Module test-json 1.0.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-json ---
    [INFO] Deleting C:test-jsontarget
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:maven-version (maven-version) @ test-json ---
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:parse-version (parse-project-version) @ test-json ---
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:timestamp-property (extract-build-year) @ test-json ---
    [INFO]
    [INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-cub3-rules) @ test-json ---
    [INFO]
    [INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-cub3-warnings) @ test-json ---
    [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
    Property 'cub-distrib-mirror-url' should be defined in your settings.
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:prepare-agent (pre-unit-test) @ test-json ---
    [INFO] argLine set to -javaagent:C:\Users\...\jacoco-ut.exec,append=true
    [INFO]
    [INFO] --- maven-jaxb2-plugin:0.13.1:generate (default) @ test-json ---
    [WARNING] No schemas to compile. Skipping XJC execution.
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-json ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 4 resources
    [INFO] skip non existing resourceDirectory C:test-jsontargetgenerated-sourcesxjc
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-json ---
    [INFO] No sources to compile
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:findbugs (findbugs) @ test-json ---
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-json ---
    [INFO] Not copying test resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-json ---
    [INFO] Not compiling test sources
    [INFO]
    [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ test-json ---
    [INFO] Tests are skipped.
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-unit-test) @ test-json ---
    [INFO] Skipping JaCoCo execution due to missing execution data file:C:test-jsontargetcoverage-reportsjacoco-ut.exec
    [INFO]
    [INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ test-json ---
    [INFO] Building jar: C:test-jsontargettest-json.jar
    [INFO]
    [INFO] --- maven-site-plugin:3.3:attach-descriptor (attach-descriptor) @ test-json ---
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:prepare-agent (pre-integration-test) @ test-json ---
    [INFO] argLine set to -javaagent:C:\Users\...\jacoco-it.exec,append=true
    [INFO]
    [INFO] >>> maven-pmd-plugin:3.2:check (default) > :pmd @ test-json >>>
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:pmd (pmd) @ test-json ---
    [INFO]
    [INFO] <<< maven-pmd-plugin:3.2:check (default) < :pmd @ test-json <<<
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:check (default) @ test-json ---
    [INFO]
    [INFO] >>> maven-pmd-plugin:3.2:cpd-check (check-duplication) > :cpd @ test-json >>>
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:cpd (cpd) @ test-json ---
    [INFO]
    [INFO] <<< maven-pmd-plugin:3.2:cpd-check (check-duplication) < :cpd @ test-json <<<
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:cpd-check (check-duplication) @ test-json ---
    [INFO]
    [INFO]
    [INFO] >>> findbugs-maven-plugin:2.5.4:check (findbugs) > :findbugs @ test-json >>>
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:findbugs (findbugs) @ test-json ---
    [INFO]
    [INFO] <<< findbugs-maven-plugin:2.5.4:check (findbugs) < :findbugs @ test-json <<<
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:check (findbugs) @ test-json ---
    [INFO]
    [INFO] --- maven-checkstyle-plugin:2.12.1:check (default) @ test-json ---
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-integration-test) @ test-json ---
    [INFO] Skipping JaCoCo execution due to missing execution data file:C:test-jsontargetcoverage-reportsjacoco-it.exec
    [INFO]
    [INFO] --- maven-install-plugin:2.5.1:install (default-install) @ test-json ---
    [INFO] Installing C:test-jsontargettest-json.jar to C:Users...test-json1.0.0.0test-json-1.0.0.0.jar
    [INFO] Installing C:test-jsonpom.xml to C:Users..test-json1.0.0.0test-json-1.0.0.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5.931 s
    [INFO] Finished at: 2016-04-19T18:16:09+02:00
    [INFO] Final Memory: 38M/444M
    [INFO] ------------------------------------------------------------------------
    C:test-json>

那么,对于jsonix模式编译器来说,什么是好的配置呢?

您不应该在Maven配置中"镜像"您的命令行XJC/Jsonix模式编译器的使用情况。与配置相比,它更适合使用约定。

因此,只需将模式和绑定文件放在src/main/resources中,然后使用-Xjsonix:打开Jsonix XJC插件

<build>
   <finalName>test-json</finalName>
   <plugins>
     <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xjsonix</arg>
                        <arg>-Xjsonix-generateJsonSchema</arg>                          
                    </args>
                    <plugins>
                        <plugin>
                            <groupId>org.hisrc.jsonix</groupId>
                            <artifactId>jsonix-schema-compiler</artifactId>
                            <version>${jsonix-schema-compiler.version}</version>
                        </plugin>
                    </plugins>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

如果您真的想重新配置源目录和目标目录等等,请检查maven-jaxb2-plugin配置(例如,请参阅备忘单)。具体来说,对于您可能需要的配置:

  • schemaDirectory
  • bindingDirectory
  • generatePackage-不推荐使用,请在绑定文件中指定包和模块名称,请参阅

最新更新