C2 Using Maven (Cont.)

Using AxisTool plug-in

Create a folder to hold the WSDL.  Create another two folders within it to hold the artifacts that will be generated for client and server side respectively. Create pom.xml for each folder including the parent folder. (The structure is just for convention, not compulsory. Besides, this hierarchical structure would also enable you to run the batch command at the top level rather than run at each individual folder)

 

Top level pom.xml should be some thing like this

 <?xml version="1.0" encoding="UTF-8"?>

<project>

    <modelVersion>4.0.0</modelVersion>

    <groupId>Hongliang.Manven.FirstHibernate.wsdl</groupId>

    <artifactId>wsdl</artifactId>

    <packaging>pom</packaging>

    <name>wsdl</name>

    <version>1.0-SNAPSHOT</version>

    <dependencies>

           <dependency>

                  <groupId>axis</groupId>

                  <artifactId>axis</artifactId>

                  <version>1.4</version>

           </dependency>

           <dependency>

                  <groupId>axis</groupId>

                  <artifactId>axis-jaxrpc</artifactId>

                  <version>1.4</version>

           </dependency>

    </dependencies>

    <modules>

           <module>hibernate-server</module>

           <module>hibernate-client</module>

    </modules>

</project>

 

As you could find:

  • <modules> describe what modules are provided in the sub structure. The value for <module> tag must match to the name of sub folder.
  • <dependencies> includes all the artifact that will be used for all modules. Rather than specified in the pom file in each individual folder, it is more convenient to put the common used ones in the top(upper) level pom file.
  • <packaging> tell maven what artifact this pom file would like to generate. For the example above, it will generate pom artifact. (Which will be used for the lower level ones)

 

A lower level pom will be some thing like this

<?xml version="1.0"?>

<project>

    <parent>

           <groupId>Hongliang.Manven.FirstHibernate.wsdl</groupId>

           <artifactId>wsdl</artifactId>

           <version>1.0-SNAPSHOT</version>

    </parent>

    <modelVersion>4.0.0</modelVersion>

    <groupId>Hongliang.Manven.FirstHibernate.wsdl</groupId>

    <artifactId>hibernate_server</artifactId>

    <name>hibernate_server</name>

    <version>1.0-SNAPSHOT</version>

    <build>

           <plugins>

                  <plugin>

                        <groupId>org.codehaus.mojo</groupId>

                        <artifactId>axistools-maven-plugin</artifactId>

                        <executions>

                               <execution>

                                      <goals>

                                             <goal>wsdl2java</goal>

                                      </goals>

                               </execution>

                        </executions>

                        <configuration>

                                <!–<sourceDirectory>${xml.repository.path}/wsdl/geoservices/spatialws/1.0.0</sourceDirectory>–>

                               <sourceDirectory>../</sourceDirectory>

                               <serverSide>true</serverSide>

                        </configuration>

                  </plugin>

           </plugins>

    </build>

</project>

As you could find from the example above

  • <parent> holds the information about the upper level artifact. Please also be aware that don’t try to include anything else either than <groupId>, <artifactId> and <version>.
  • <plugin> specifies the plugin that will be used to help to build the project. Plugin and its artifactId could be found from its repository provided by different workgroup such as Maven Central repository. Snapshots and Codehaus repository. For more details like usage and goals could be found from its description on providers’ website.
  • <sourceDirectory> define the directory where the wsdl file located. (Be aware that all wsdl files in the folder will be processed)
  • <serverSide> defines whether the output is for server side.

 

${xml.repository.path} in the example has been defined in the setting.xml in the m2 folder. It shows the possibilities to define any global property in the setting.xml file. (Of course, you can also define it in the upper level pom file)

 

Once the pom files are built, run the following command at the level required.

mvn install

 

Building and using your own plug-in

As discussed in the preceding topic, inheriting from the upper level artifact is actually treated the legacy as additional plug-in created on the fly. In order to make it reusable for the future, you need to store it in the (remote) repository as customized plug-in.

 

To build your own plug-in, first you need to create an associated pom file and state that output artifact is maven-plugin

<packaging>maven-plugin</packaging>

 

You should be careful with the artifactId and groupId, as this will be relevant to the repository directory

    <groupId>gdc.plugins</groupId>

    <artifactId>maven-deployws-plugin</artifactId>

 

There is no difference in structure for customized and standard (maven, mojo and etc) repository.

 

<groupId>gdc.plugins</groupId> is telling that the artifact is in the folder gdc inside plugins folder in side repository. <artifactId>maven-deployws-plugin</artifactId> is telling that the folder name of the artifact is maven-deployws-plugin. In another word, the path will be something like this

…\gdc\plugins\maven-deployws-plugin

 

Of course you also need to specify repository url in either setting.xml or the pom file you are going to use.

      <repositories>

       <repository>

         <id>internal</id>

         <name>Internal Repository</name>

         <url>file:////172.19.18.23/Development/maven-repository</url>

         <url>http://terrapin.internal.graphdata.co.uk/maven/</url&gt;

       </repository>

       <repository>

         <id>Codehaus</id>

         <url>http://repository.codehaus.org/</url&gt;

         <snapshots>

           <enabled>false</enabled>

         </snapshots>

         <releases>

           <enabled>true</enabled>

         </releases>

       </repository>

     </repositories>

 

Once you have correctly build the pom file, run the install command and copy the output to the directory as specified (based on repository/groupId/artifactId)

 

Building your own dependencies and repository

Of course you could also build your own dependencies and repository. For example, when you use the wsdl2java to create the artifact for web service, you would normally want to include the jar file generated into your web service project (it’s not mandatory, as alternatively you can copy all the source files generated into your project). How would you be able to use this jar file in Maven convention rather than import through IDE directly? Yes, use it as a dependency.

 

Since we have created wsdl project with Maven as well (the artifact created by wsdl project has been copied to the local repository and therefore you could refer it directly), all we need to do is just to but the following fragment into the pom file.

 

           <dependency>

            <groupId>Hongliang.Manven.FirstHibernate.wsdl</groupId>

            <artifactId>hibernate_server</artifactId>

            <version>1.0-SNAPSHOT</version>

           </dependency>    

 

You should also find conformed structure in the local repository directory.

                       

If you are using eclipse with Maven, you can just run the following command to rebuild your workspace

Mvn eclipse:clean eclipse:eclipse

 

Then you should be able to the hibernate_server-1.0-SNAPSHOT.jar file has been add to your libraries.

Using Maven with different JDK version            

Maven 2.0 is using jdk 1.1 as its default. Therefore you have to reconfigure it to enable you to use the features of the other version

 

 

    <build>

           <plugins>

                  <plugin>

                        <groupId>org.apache.maven.plugins</groupId>

                        <artifactId>maven-compiler-plugin</artifactId>

                        <version>2.0.1</version>

                        <configuration>

                               <source>1.5</source>

                               <target>1.5</target>

                        </configuration>

                  </plugin>

           </plugins>

    </build>     

http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.0.1/

 

Advertisements
This entry was posted in Maven. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s