jsonix-schema-compiler Maven用法

时间:2016-04-19 16:57:19

标签: json xsd jsonix

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

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

<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-json\target
    [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-json\target\generated-sources\xjc
    [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-json\target\coverage-reports\jacoco-ut.exec
    [INFO]
    [INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ test-json ---
    [INFO] Building jar: C:\test-json\target\test-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-json\target\coverage-reports\jacoco-it.exec
    [INFO]
    [INFO] --- maven-install-plugin:2.5.1:install (default-install) @ test-json ---
    [INFO] Installing C:\test-json\target\test-json.jar to C:\Users\...\test-json\1.0.0.0\test-json-1.0.0.0.jar
    [INFO] Installing C:\test-json\pom.xml to C:\Users\..\test-json\1.0.0.0\test-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-schema-compiler的良好配置是什么?

1 个答案:

答案 0 :(得分:1)

你不应该&#34;镜像&#34;您在Maven配置中的命令行XJC / Jsonix Schema Compiler用法。使用约定优于配置,它可以工作得更多。

所以只需将你的模式和绑定文件放在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 coniguration(例如,请参阅cheat sheet)。具体而言,对于您可能需要的配置:

  • schemaDirectory
  • bindingDirectory
  • generatePackage - 不建议使用,请在绑定文件中指定包和模块名称,请参阅this
相关问题