Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Monday, May 1, 2017

Syntax for Maven / Eclipse Lifecycle mapping

New syntax for specifying lifecycle mapping metadata

A new syntax has been introduced to simplify lifecycle mapping metadata for plugin executions, using processing instructions within plugin/executions/execution nodes.
processing instructions for lifecycle mapping
Supported syntax:
  • <?m2e ignore?> this execution will be ignored;
  • <?m2e execute?> this execution will be executed once on project import;
  • <?m2e execute onConfiguration?> this execution will be executed on every Project Configuration update;
  • <?m2e execute onIncremental?> this execution will be executed on every incremental build;
  • <?m2e execute onConfiguration,onIncremental?> this execution will be executed on every Project Configuration update and every incremental build;
  • <?m2e configurator configuratorId?> this execution will be delegated to the matching m2e configurator.
Each instruction can be placed in the <execution> node, this way it applies on this exact execution or on any execution of the same plugin with the same executionId in child pom. It can also be placed in a <plugin> node, this way it acts the same as a dedicated <pluginManagement> section which lists all goals of this plugin.
Please be aware there are currently no Quick Fixes available to automatically inject these new instructions when a “Plugin Execution Not Covered” error marker is found.

Tuesday, March 14, 2017

settings.xml mirrors repositories proxy

 <distributionManagement>
  <repository>
   <id>fxg-releases</id>
   <url>https://nexus.x.com:8443/nexus/content/repositories/fxg-releases</url>
  </repository>
  <snapshotRepository>
   <id>fxg-snapshots</id>
   <url>https://nexus.x.com:8443/nexus/content/repositories/fxg-snapshots</url>
  </snapshotRepository>
  <site>
   <id>mvnown</id>
   <url>scpexe://maven.x.com/var/fedex/scm/mvn/httproot/site/${project.artifactId}/${project.artifactId}-${project.version}</url>
  </site>
 </distributionManagement>


SETTINGS XML 


<settings>
 <!-- Switching to c:/temp for the "document and settings" spacing issues some projects have when stepping out of the java realm to perform 
  function by a plugin. -->
 <localRepository>${java.io.tmpdir}/${user.name}/repository</localRepository>
 <interactiveMode>true</interactiveMode>
 <proxies>
  <proxy>
   <active />
   <port>3128</port>
   <host>internet.proxy.fedex.com</host>
   <id>FedEx VPN Proxy</id>
  </proxy>
 </proxies>
 <servers>
  <server>
   <id>releases</id>
   <username>scm</username>
   <password>****</password>
  </server>
  <server>
   <id>snapshots</id>
   <username>dev</username>
   <password>LKLKLJLKJL</password>
  </server>
 </servers>
 <mirrors>
  <mirror>
   <id>proxy</id>
   <name>Maven Proxy</name>
   <url>http://maven.x.com:9999/nexus/content/groups/m2/</url>
   <mirrorOf>external:*,!my-nexus</mirrorOf>
  </mirror>
  <mirror>
   <id>my-nexus</id>
   <name>
    Maven Repository Manager running on 
   </name>
   <url>https://nexus.x.com:8443/nexus/content/groups/m2/</url>
   <mirrorOf>*</mirrorOf>
  </mirror>
 </mirrors>
 <profiles>
  <profile>
   <id>nexus</id>
   <repositories>
    <repository>
     <id>corp-nexus-snapshots</id>
     <url>https://nexus.x.com:8443/nexus/content/repositories/fxg-snapshots</url>
     <releases>
      <enabled>false</enabled>
     </releases>
     <snapshots>
      <enabled>true</enabled>
     </snapshots>
    </repository>
    <repository>
     <id>corp-nexus-releases</id>
     <url>https://nexus.x.com:8443/nexus/content/repositories/fxg-releases</url>
     <releases>
      <enabled>false</enabled>
     </releases>
     <snapshots>
      <enabled>true</enabled>
     </snapshots>
    </repository>
   </repositories>
  </profile>
 </profiles>
 <activeProfiles>
  <activeProfile>nexus</activeProfile>
 </activeProfiles>
</settings>



Wednesday, December 28, 2016

internal maven properties

This page extracts a few classical values:
  • ${project.basedir} 
    • This references to the root folder of the module/project (the location where the current pom.xml file is located)
POM properties referencing useful build locations, with default values defined in the Super POM:
  • ${project.build.directory}
    • This represents by default the target folder.
  • ${project.build.outputDirectory}
    • This represents by default the target/classes folder.
  • ${project.build.testOutputDirectory}
    • This represents by default the target/test-classes folder.
  • ${project.build.sourceDirectory}
    • This represents by default the src/main/java folder.
  • ${project.build.testSourceDirectory}
    • This represents by default the src/test/java folder.
You can use further properties like the following:
  • ${project.build.finalName}
    • This is by default defined as ${project.artifactId}-${project.version}.
  • ${project.version}
    • This can be used at locations where you have to write a literal version otherwise, in particular if you are in a multi-modules build for inter modules dependencies.
User Settings
The settings.xml elements could be referenced by using things like this (see also at the Super POM):
  • ${settings.localRepository}
    • which references the location of the local repository. This is by default ${home}/.m2/repository.
Values are evaluated in sequence from different syntaxes:
valueevaluation resultcommon examples
project.*
pom.* (deprecated)
* (deprecated)
POM content (see POM reference)${project.version}
${project.build.finalName}
${project.artifactId}
${project.build.directory}
project.basedir
pom.basedir (deprecated)
basedir (deprecated)
the directory containing the pom.xml file${project.basedir}
project.baseUri
pom.baseUri (deprecated)
the directory containing the pom.xml file as URI${project.baseUri}
build.timestamp
maven.build.timestamp
the UTC timestamp of build start, in yyyy-MM-dd'T'HH:mm:ss'Z' default format, which can be overridden with maven.build.timestamp.format POM property${maven.build.timestamp}
*user properties, set from CLI with -Dproperty=value${skipTests}
*model properties, such as project properties set in the pom${any.key}
maven.homeThe path to the current Maven home.${maven.home}
maven.versionThe version number of the current Maven execution (since 3.0.4). For example, "3.0.5".${maven.version}
maven.build.versionThe full build version of the current Maven execution (since 3.0.4). For example, "Apache Maven 3.2.2 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19T14:51:28+01:00)".${maven.build.version}
*Java system properties (see JDK reference)${user.home}
${java.home}
env.*
*
environment variables${env.PATH}
settings.*Local user settings (see settings reference)${settings.localRepository}

Wednesday, April 10, 2013

Ant Mojo Debuging: turning on ant-tasks logging from a maven-plugin or command line.

Here you have a legacy ant build.xml that you would like to integrate as an Ant Mojo (which is not the same as the antrun-plugin). How can we switch on the debugging from maven on the ant side... following the tutorial we create a hello ant execution... and this results in the hello.build.xml and hello.mojos.xml. Next we skip to the "Built It! Run It!" section and change the following to our projects pom.xml that is using the hello plugin.
$ mvn org.myproject.plugins:hello-plugin:hello
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.410s
[INFO] Finished at: Wed Apr 10 09:53:12 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Now change the call and add -DantMessageLevel=[info|debug|trace].
$ mvn org.myproject.plugins:hello-plugin:hello -DantMessageLevel=debug
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---
Project base dir set to: /Users/tmp
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml with URI = file:///var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Setting ro project property: ant.file.null -> /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Project base dir set to: /Users/akaan/tmp
 +Target: 
 +Target: hello
Adding reference: project
Adding reference: session
Adding reference: mojoExecution
Setting ro project property: messageLevel -> debug
Setting ro project property: basedir -> /Users/tmp
Build sequence for target(s) `hello' is [hello]
Complete build sequence is [hello, ]

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.413s
[INFO] Finished at: Wed Apr 10 09:55:09 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Or if you need to pass the configuration item in the plugin definition itself use messageLevel.
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.myproject.tests</groupId>
  <artifactId>hello-plugin-tests</artifactId>
  <version>1.0</version>
  
  <name>Test Project</name>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.myproject.plugins</groupId>
        <artifactId>hello-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        
        <configuration>
          <name>John</name>


          <messageLevel>debug</messageLevel> 


        </configuration>
        
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>one</goal>
              <goal>two</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Thursday, March 28, 2013

onliner - JAXBElement XJC Bindings and XMLRootElement creation for any schema

Some schema's do not get generated with the XMLRootElements which can get you into trouble marshalling Java 2 XML. See the error below
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.tibco.xmlns.applicationmanagement.ApplicationType" as an element because it is missing an @XmlRootElement annotation]
 at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
 at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
 at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:626)
 ... 25 more
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "com.tibco.xmlns.applicationmanagement.ApplicationType" as an element because it is missing an @XmlRootElement annotation
 at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:216)
 at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:286)
 at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
 at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
 ... 27 more
[ERROR] 
With the XJC bindings we can fix this however can be tedious going thru all the elements.... Boring.... so lets make a oneliner.... Here a one liner that will solve that and will generate the annotation section for your xcj.bindings or jaxb.bindings... Generating the XMLRootElement on bindings (requirements for perl will be XML::Simple see cpan)
perl -MXML::Simple -e 'BEGIN { use Data::Dumper; } $x=XMLin("./src/main/schema/5.5/ApplicationManagement.xsd");foreach (keys %{$x->{"complexType"}}) { printf "<jaxb:bindings node=\"xs:complexType[\@name=%c%s%c]\">
<annox:annotate><annox:annotate annox:class=\"javax.xml.bind.annotation.XmlRootElement\" name=\"%s\"/></annox:annotate></jaxb:bindings>\n",0x27,$_,0x27,$_ if $_; };'
Generates the output on the console:
<jaxb:bindings node="xs:complexType[=ActionType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="ActionType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=ServiceType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="ServiceType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=ServiceInstanceType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="ServiceInstanceType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=anyObject]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="anyObject"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=ApplicationType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="ApplicationType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=NVPairType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="NVPairType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=RepoInstanceType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="RepoInstanceType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=RemoteRepoInstanceType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="RemoteRepoInstanceType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=EventType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="EventType"/></annox:annotate></jaxb:bindings>
<jaxb:bindings node="xs:complexType[=BWServiceType]"><annox:annotate><annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="BWServiceType"/></annox:annotate></jaxb:bindings>
Signings-MacBook-Pro:tibco-appmanage-schema $ 
THe end result as a XJC bindings file... which can be included in your XJC generation, in my case the maven plugin:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:annox="http://annox.dev.java.net"
  xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
  version="2.1">
  <jaxb:bindings schemaLocation="ApplicationManagement.xsd"
    node="/xs:schema">
    <jaxb:globalBindings generateIsSetMethod="true"
      collectionType="java.util.ArrayList">
    </jaxb:globalBindings>
    <jaxb:bindings node="xs:complexType[@name=ActionType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="ActionType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=ServiceType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="ServiceType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=ServiceInstanceType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="ServiceInstanceType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=anyObject]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="anyObject" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=ApplicationType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="ApplicationType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=NVPairType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="NVPairType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=RepoInstanceType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="RepoInstanceType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=RemoteRepoInstanceType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="RemoteRepoInstanceType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=EventType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="EventType" />
      </annox:annotate>
    </jaxb:bindings>
    <jaxb:bindings node="xs:complexType[@name=BWServiceType]">
      <annox:annotate>
        <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
          name="BWServiceType" />
      </annox:annotate>
    </jaxb:bindings>
  </jaxb:bindings>
</jaxb:bindings>
And the declaration of the maven plugin....
      <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.3</version>
        <executions>
          <execution>
            <id>generate-domain1</id>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <strict>true</strict>
          <schemaDirectory>src/main/schema/${schema.version}</schemaDirectory>
          <schemaIncludes>
            <value>scm-tibco-project.xsd</value>
          </schemaIncludes>
          <bindingIncludes>
            <include>xjc.bindings</include>
          </bindingIncludes>
          <verbose>true</verbose>
          <extension>true</extension>
          <args>
            <arg>-Xannotate</arg>
            <arg>-Xequals</arg>
            <arg>-XtoString</arg>
            <arg>-XhashCode</arg>
          </args>
          <generateDirectory>${project.build.directory}/generated-sources/xjc
          </generateDirectory>
          <plugins>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics</artifactId>
              <version>0.6.0</version>
            </plugin>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics-annotate</artifactId>
              <version>0.6.0</version>
            </plugin>
          </plugins>
        </configuration>
      </plugin>

Friday, August 17, 2012

find all the dependencies

usr@host:~/BUILD/foo-bar-root
$ find . -name 'pom.xml' -print -exec perl -ne 'BEGIN {my @k;} if (// ... /<\/plugin>/) { push @k, $_; } else { @k=undef;};  if (@k and grep {/<\/plugin>/} @k and grep {/pmd/} @k ) {print join("",@k);@k=undef}  ' {} \; -print 

Adding XmlRootElement

 
  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.7.4</version>
    <executions>
     <execution>
      <id>generate-domain1</id>
      <goals>
       <goal>generate</goal>
      </goals>
      <configuration>
       <strict>true</strict>
       <schemaDirectory>src/main/schema</schemaDirectory>
       <schemaIncludes>
        <value>*.xsd</value>
       </schemaIncludes>
       <bindingIncludes>
        <include>bindings.xjb</include>
       </bindingIncludes>
       <verbose>true</verbose>
       <extension>true</extension>
       <args>
        <arg>-Xannotate</arg>
       </args>
       <generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
       <plugins>
        <plugin>
         <groupId>org.jvnet.jaxb2_commons</groupId>
         <artifactId>jaxb2-basics</artifactId>
         <version>0.6.0</version>
        </plugin>
        <plugin>
         <groupId>org.jvnet.jaxb2_commons</groupId>
         <artifactId>jaxb2-basics-annotate</artifactId>
         <version>0.6.0</version>
        </plugin>
       </plugins>
      </configuration>
     </execution>
    </executions>
   </plugin>

XJC XmlRootElement and SOAPAction, WebServiceTemplate spring-ws

If you want to create client stubs by means of spring-ws and you do not have the notation of the @Endpoint and @Payload definitions it is sometimes problematic getting the right SOAPAction and XmlRootElement defined.

The first try you can generate with the xjc:simple binding
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="xjc annox">
<jaxb:globalBindings>
 <xjc:simple />
</jaxb:globalBindings>
 
<!-- FILE: PickupAudit.xsd --> 

 <jaxb:bindings schemaLocation="PickupAudit.xsd" node="/xs:schema">
   <jaxb:bindings node="xs:complexType[@name='PickupAudit']">
      <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="PickupAudit" />
      </annox:annotate>
    </jaxb:bindings>
   <jaxb:bindings node="xs:complexType[@name='PickupAuditType']">
      <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="PickupAudit" />
      </annox:annotate>
    </jaxb:bindings>
  </jaxb:bindings>

</jaxb:bindings>


Generating the @XmlRootElement("something")
<plugin>
 <groupId>org.jvnet.jaxb2.maven2</groupId>
 <artifactId>maven-jaxb2-plugin</artifactId>
 <version>0.7.4</version>
 <executions>
  <execution>
   <id>generate-domain1</id>
   <goals>
    <goal>generate</goal>
   </goals>
   <configuration>
    <strict>true</strict>
    <schemaDirectory>src/main/schema</schemaDirectory>
    <schemaIncludes>
     <value>*.xsd</value>
    </schemaIncludes>
    <bindingIncludes>
     <include>bindings.xjb</include>
    </bindingIncludes>
    <verbose>true</verbose>
    <extension>true</extension>
    <args>
     <arg>-Xannotate</arg>
    </args>
    <generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
    <plugins>
     <plugin>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>0.6.0</version>
     </plugin>
     <plugin>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics-annotate</artifactId>
      <version>0.6.0</version>
     </plugin>
    </plugins>
   </configuration>
  </execution>
 </executions>
</plugin>

Friday, June 3, 2011

Maven XJC generation XMLSchemaType for date / dateTime missing

I've noticed a mishap with the xsd:date and xsd:dateTime conversions to Java objects. There are posts out there to avoid it or just modify the generated code but thats not what I want.

With the xsd defined as:

The 1.1 version of the com.sun.tools.xjc.maven2:maven-jaxb-plugin will not generate the XMLSchemaType "dateTime" however the 1.1.1 version does generate the correct XMLSchemaType.

By comparison if you choose to use the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin it will generate the XMLSchemaType.

Here the comparison between 1.1 and 1.1.1 of the com.sun.tools.xjc.maven2:maven-jaxb-plugin.



<plugin>
                <groupId>com.sun.tools.xjc.maven2</groupId>
                <artifactId>maven-jaxb-plugin</artifactId>
                <version>1.1.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <removeOldOutput>true</removeOldOutput>
                    <schemaDirectory>src/main/schema/</schemaDirectory>
                    <includeSchemas>
                        <includeSchema>**/*.xsd</includeSchema>
                    </includeSchemas>
                    <strict>true</strict>
                    <verbose>false</verbose>
                    <extension>true</extension>
                    <readOnly>yes</readOnly>
                </configuration>
            </plugin>

Thursday, October 21, 2010

JAXB Serializable Binding with Maven

Generating the classes from a xsd where the classes implement the java.io.Serializable interface for serialization between nodes.

.   ---> pom.xml
./.settings
./src
./src/main
./src/main/binding
    ---> binding.xjb
./src/main/java
./src/main/java/com
./src/main/java/META-INF
./src/main/resources
    ---> my.xsd

The maven plugin configuration in the pom.xml
<plugins>
            <plugin>
                <groupid>org.jvnet.jaxb2.maven2</groupid>
                <artifactid>maven-jaxb2-plugin</artifactid>
                <version>0.7.4</version>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xfluent-api</arg>
                    </args>
                    <schemadirectory>src/main/resources</schemadirectory>
                    <bindingdirectory>src/main/binding</bindingdirectory>
                    <plugins>
                        <plugin>
                            <groupid>net.java.dev.jaxb2-commons</groupid>
                            <artifactid>jaxb-fluent-api</artifactid>
                            <version>2.1.8</version>
                        </plugin>
                    </plugins>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

The content of the binding.xjb
<jxb:bindings 
    version="1.0" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jxb:extensionBindingPrefixes="xjc">
    <jxb:bindings>
        <jxb:globalBindings>
            <xjc:serializable/>
        </jxb:globalBindings>
    </jxb:bindings>
</jxb:bindings>

The result:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "application", propOrder = {
"name",
"version",
"state",
"serverName"
})
public class Application
implements Serializable
{

@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String version;
@XmlElement(required = true)
protected String state;