Thursday, June 12, 2014

Generating JAXB artifacts from XSD/WSDL through Maven

Generating JAXB artifacts from XSD/WSDL through Maven

The maven-jaxb2-plugin can be used to generate the java classes from both XSD/WSDL.

Plugin configuration in Pom.xml

The below plug in configuration can be used in the pom.xml file to generate the sources.
<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.7.3</version>
  <executions>
    <execution>
      <id>app1-stub-generation</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <schemaIncludes>
          <include>*.xsd</include>
        </schemaIncludes>
        <generatePackage>com.thomson.ecom.service.bean.demo</generatePackage>
        <clearOutputDir>false</clearOutputDir>
        <generateDirectory>src/main/java</generateDirectory>
        <strict>true</strict>
      </configuration>
    </execution>
 
 
  </executions>
</plugin>

Change the include accordingly to generate for wsdl -   <include>*.wsdl</include>

Generate the sources

To generate the sources, Right click on pom.xml-->Run As-->Maven generate-sources


This will generate all the java classes to src/main/java


Wednesday, June 11, 2014

Configuring JAXB2-Maven-Plugin not to clear the outputdirectory

Configuring JAXB2-Maven-Plugin not to clear the outputdirectory

JAXB2-Maven-Plugin will help us to generate the java classes from the xsd.
By default the plugin clears the existing contents in the ouputdirectory and generate the new java classes into the outputdirectory.

Some cases we may need to generate the java classes from multiple source xsd's so we have to configure the plugin not to clear the outputdirectory.

Yo have to add <clearOutputDir>false</clearOutputDir> in the plugin configuration.

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The schema directory or xsd files. -->
                <schemaDirectory>${basedir}/src/main/resources</schemaDirectory>
                <!-- The package in which the source files will be generated. -->
                <packageName>com.service.bean.demo</packageName>
                 <clearOutputDir>false</clearOutputDir>
                <!-- The working directory to create the generated java source files. -->
                <outputDirectory>${basedir}/src/main/java</outputDirectory>
            </configuration>
        </plugin>


Tuesday, June 10, 2014

Changing the default Maven repository location in eclipse

Changing the default Maven repository location in eclipse

Sometimes we may required to modify the default maven repository location to custom location for the eclipse project.
Eclipse project will have the variable M2_REPO defined as read only.


The following steps will help as to change the default Mavan repository location.

Modify the settings.xml file in the <<USER_HOME>>/.m2 and add the localRepository value accordingly.



If the .m2 folder ia not available in the USER_HOME create the same(md .m2) and also create a settings.xml file and update the file with the following contents(change the value of localrepository and the repository url accordingly)



Monday, August 5, 2013

Changing the Default Maven Repository Location in Eclipse

Changing the Default Maven Repository Location in Eclipse

Sometimes we may need to change the default repository location of the maven in eclipse, the following steps will help us to do the same.

Steps to change the default repository location of the maven in eclipse

Change the repository path(location of the local repository path) in $MAVEN_HOME\conf\settings.xml file


Change the Settings.xml location in eclipse preferences

Browse the settings.xml file automatically the repository path will be displayed,Click on Apply then Click on Ok.