jsonix-schema-compiler Maven 使用

问题描述 投票:0回答:1

我尝试根据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 的良好配置是什么?

json xsd jsonix
1个回答
1
投票

您不应该在 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
    - 不建议使用,而是在绑定文件中指定包和模块名称,请参阅this
© www.soinside.com 2019 - 2024. All rights reserved.