3

I'm trying to obtain the Java model for the FHIR R4 specification. To accomplish this task, I downloaded the JSON Schema and I try to use jsonschema2pojo maven plugin to generate the source code.

I create a simple Maven project and I put the JSON Schema under src/main/resources/schema. So, I defined the following pom:

<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.example</groupId>
    <artifactId>fhir-generator</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.9.2</version>
        </dependency>
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>1.0.1</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
                    <targetPackage>com.example.fhir</targetPackage>
                    <useCommonsLang3>true</useCommonsLang3>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

When I run the goal package I obtain the folliwing output:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for come.example:fhir-generator:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 24, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building fhir-generator 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- jsonschema2pojo-maven-plugin:1.0.1:generate (default) @ fhir-generator ---
[WARNING] useCommonsLang3 is deprecated. Please remove it from your config.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ fhir-generator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ fhir-generator ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ fhir-generator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ fhir-generator ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ fhir-generator ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ fhir-generator ---
[INFO] Building jar: Z:\work\backend\fhir-generator\target\fhir-generator-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.921 s
[INFO] Finished at: 2019-07-30T11:21:25+02:00
[INFO] Final Memory: 12M/208M
[INFO] ------------------------------------------------------------------------

The problem is that no classes were generated in target/generated-sources folder. Any ideas about it? Tnx in advance

xcesco
  • 4,690
  • 4
  • 34
  • 65
  • 1
    I'm not familiar with these jsonschema2pojo - but json schema and the tools are immature in regard to some of the features that FHIR hammers on, so I woluldn't be surprised if you have problems. Have you looked at HAPI-FHIR? – Grahame Grieve Jul 30 '19 at 11:50
  • Not jet! I will have a look at HAPI-FHIR. Tnx! – xcesco Jul 30 '19 at 15:04

2 Answers2

3

By default jsonschema2pojo plugin generates the files to target/java-gen/ folder, not the one you have specified.

user07
  • 319
  • 2
  • 8
0

@xcesco - Each maven tag such as - sourceDirectory, and targetPackage, has specific meaning. You can check for more details at plugin page.

Try providing outputdirectory.

<plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <!--<version>1.2.1</version>-->
                <executions>
                    <execution>
                        <id>generate-message-contracts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>project path..\directory\</sourceDirectory>
                            <outputDirectory>${basedir}/directory/src/gen/java</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Vivek Tyagi
  • 691
  • 1
  • 4
  • 4