Child pages
  • Adding Data Model Generation to a project

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Add directory src/main/dmgen with datamodel.xml and generator.xml
      • Specify entities and their attributes in datamodel.xml
      • Specify what the generator should do in generator.xml (in an API project usually generating dtos and joinDtos)#
      • Contents of generator.xml e.g.

        Code Block
        collapsetrue
        <GeneratorConfig>
        	<Generate concept="dto" package="at.iteg.tis.prediction.api.dto"/>
        	<Generate concept="joinDto" package="at.iteg.tis.prediction.api.joinDto" dtoPackage="at.iteg.tis.prediction.api.dto"/>
        </GeneratorConfig>
  2.  In pom.xml: Add resources to build/resources section, e.g.:

    Code Block
    collapsetrue
          <resource>
            <directory>src/generated/java</directory>
            <includes>
              <include>at/iteg/tis/prediction/api/dto/*.java</include>
              <include>at/iteg/tis/prediction/api/joinDto/*.java</include>
            </includes>        
          </resource>
          <resource>
          	<directory>src/main</directory>
          	<includes>
          		<include>dmgen/datamodel.xml</include>
          	</includes>
          </resource> 
  3. In pom.xml: Register maven-clean plugin

    Code Block
    collapsetrue
      <plugin>
    	<artifactId>maven-clean-plugin</artifactId>
    	<configuration>
    	  <filesets>
    	    <fileset>
    	      <directory>src/generated/java</directory>
    	      <includes>
    		<include>at</include>
    		<include>**/*.java</include>						
    	      </includes>
    	      <followSymlinks>false</followSymlinks>
    	    </fileset>
    	  </filesets>
    	</configuration>
      </plugin>    
  4. In pom.xml: Register dmgen plugin

    Code Block
    collapsetrue
    		<plugin>
    			<groupId>org.clazzes.dmgen</groupId>
    			<artifactId>maven-dmgen-plugin</artifactId>
    			<executions>
    				<execution>
    					<phase>generate-sources</phase>
    					<goals>
    						<goal>dmgen</goal>
    					</goals>
    				</execution>
    			</executions>
    			<configuration>
    				<dmSpecFile>${basedir}/src/main/dmgen/datamodel.xml</dmSpecFile>
    				<dmConfigFile>${basedir}/src/main/dmgen/generator.xml</dmConfigFile>
    				<outputDir>${basedir}/src/generated</outputDir>
    			</configuration>
    		</plugin>

...