Srinivasan Chikkala's Weblog
Archives
« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today
Click me to subscribe
Search

Links
 

Today's Page Hits: 9

« JBI Examples - Devel... | Main | Updated JBI CDK (JBI... »
Friday Apr 20, 2007
Maven Archetypes for JBI Component projects

I have created two maven archetypes for creating maven based projects for developing JBI Components (Service Engines and Binding Components). The maven projects created using these archetypes are complete projects which are ready to build and test ( unit and integration test ) a working JBI Component. The maven project created for the JBI Component will have a maven project metadata (pom.xml), ant build scripts,  sample code that implements either BC or SE,  sample junit test and integration test code. The project can be buildable using maven build lifecycle or ant build lifecycle to completely build and test the component. The sample source code and the source structure for component implementation is same as that explained in the article JBI Examples - Developing JBI Components.

How to create maven project for SE or BC

To create  SE or BC maven projects, "create" goal of the maven archetype plugin should be executed with SE or BC archetypes configuration parameters.  Maven version 2.0.4 or 2.0.5 is required to correctly download the archetype plugin. If you have setup the build environment for open-esb or open-jbi-components projects, you already have the required maven setup. If not, download and install Maven2 version : 2.0.5 from http://maven.apache.org/

 The following configuration parameters effect the code generated in the maven project for SE or BC

Service Engine(SE) archetype command

To create a service engine maven project, use maven-archetype-jbi-se  archetype. The command that creates the service engine project using this archetype is as follows.

Note that all the options to the archetype:create must be specified in a single line.
Service Engine project create command

mvn archetype:create
-DremoteRepositories=http://download.java.net/maven/2/
-DarchetypeGroupId=open.jbi.components.maven.archetype
-DarchetypeArtifactId=maven-archetype-jbi-se
-DarchetypeVersion=0.1
-DgroupId=<your.component.group.id>
-DartifactId=<yourEngineName>
-DpackageName=<your.component.package>
-Dversion=<your project version>


The following is an example of the SE project create command that creates service engine maven project with  jbi component name "my-first-se"  in a directory "my-first-se" and creates a sample code specific to the SE in "com.example.engine" along with other build and test artifacts.

Note that all the options to the archetype:create must be specified in a single line.
Example Service Engine project create command

mvn archetype:create
-DremoteRepositories=http://download.java.net/maven/2/
-DarchetypeGroupId=open.jbi.components.maven.archetype
-DarchetypeArtifactId=maven-archetype-jbi-se
-DarchetypeVersion=0.1
-DgroupId=my.group.id
-DartifactId=my-first-se
-DpackageName=com.example.engine
-Dversion=1.0-test


Binding Component(BC) archetype command

To create a binding component maven project, use maven-archetype-jbi-bc  archetype. The command that creates the binding component project using this archetype is as follows.

Note that all the options to the archetype:create must be specified in a single line.
Binding Component (BC)  project create command

mvn archetype:create
-DremoteRepositories=http://download.java.net/maven/2/
-DarchetypeGroupId=open.jbi.components.maven.archetype
-DarchetypeArtifactId=maven-archetype-jbi-bc
-DarchetypeVersion=0.1
-DgroupId=<your.component.group.id>
-DartifactId=<yourBindingName>
-DpackageName=<your.component.package>
-Dversion=<your project version>


The following is an example of the BC project create command that creates binding component maven project with  jbi component name "my-first-bc"  in a directory "my-first-bc" and creates a sample code specific to the BC in "com.example.binding" along with other build and test artifacts.

Note that all the options to the archetype:create must be specified in a single line.
Example Binding Component project create command

mvn archetype:create
-DremoteRepositories=http://download.java.net/maven/2/
-DarchetypeGroupId=open.jbi.components.maven.archetype
-DarchetypeArtifactId=maven-archetype-jbi-bc
-DarchetypeVersion=0.1
-DgroupId=my.group.id
-DartifactId=my-first-bc
-DpackageName=com.example.binding
-Dversion=1.0-test


How to Build  SE or BC maven project

In the maven project for JBI Component ( BC or SE ), the code generated and the filesystem structure are similar to what is describes in the JBI Examples - Developing JBI Components.  The difference is that the component name and component specific classes are generated according to the project creation settings and a maven project metadata ( pom.xml ) is generated to build the project from maven build environment.

The build lifecycle for  both SE and BC projects are same.  During the build, when a maven build phase is executed, the maven build lifecycle phases call the corresponding ant build script targets ( ant build lifecycle ) where the actual action for compile, package and test the components takes place.

The following maven build lifecycle phases can be executed to perform compile, package, unit testing and integration testing of the component.

build phase
Description
mvn compile Compiles the  component sources
mvn test-compile Compiles test sources and component sources
mvn test Runs junit tests after compiling component sources and test sources.
mvn package Packages compiled component sources into JBI component installation zip archive file. It runs junit tests by executing test phase before packaging.
mvn integration-test Runs integration test after calling package and test phase. The integration test  installs and starts the component, build, deploy and starts test service assembly if needed,  and runs the test client code, then undeploys test service assembly if needed and then uninstalls the component. The results of the test will be in Output.xml in the test results directory.
mvn install Executes all the above phases and then installs the component installer zip archive file to the maven local repository.
mvn clean Cleans the output directories ( build, dist ) and then try to uninstall the component from the server. If uninstall fails, the results are shown, but the build will not fail.

Before building and testing the component from maven do the following
  1. Install glassfish  ( download and install from https://glassfish.dev.java.net/ )
  2. Set the JV_GFBASE environment variable to the glassfish V2 installation root ( e.g. set JV_GFBASE=C:/Sun/glassfish ) .
  3. Edit pom.xml (optional) - only required if the glassfish is not installed with default settings or JV_GFBASE environment variable is not set.
    1. Set the glassfish home :  under <properties> element set glassfish.home property value to the glassfish v2 installation root.
    2. Set the jbi admin settings (optional) :  under <properties> element set jbi.host, jbi.port, jbi.username, jbi.password properties to glassfish admin settings.
  4. Run the glassfish (optional)  only required for the integration-test and install phases of the project builds.
  5. Execute build lifecycle phases using "mvn" command.
Note:  To do the integration-test of the  generated BC project,  a service engine from the generated SE project should be installed and started.  So, before executing the "integration-test" of the generated BC project,  execute the "integration-test" phase of the SE project with "-Dtest.uninstall.skip=true" to not uninstall the SE.

Sample integration testing steps for the SE and BC projects created from the example commands shown above.

asadmin start-domain domain1 - to start the glassfish
cd my-first-se
mvn -Dtest.uninstall.skip=true integration-test
cd my-first-bc
mvn integration-test
mvn clean
cd my-first-se
mvn clean
asadmin stop-domain domain1 - to stop the glassfish

Building project with Apache Ant (Optional)

If you would like to build and test the project using ant outside the maven, do the following setup before using the ant targets directly from ant.
  1. Install glassfish  ( download and install from https://glassfish.dev.java.net/ )
  2. Set the JV_GFBASE environment variable to the glassfish v2 installation root ( e.g. set JV_GFBASE=C:/Sun/glassfish ) .
  3. Edit build.properties file
    1. Set the glassfish home : set glassfish.home property value to the glassfish v2 installation root.
    2. Set the jbi admin settings (optional) :  set jbi.host, jbi.port, jbi.username, jbi.password properties to glassfish admin settings if the glassfish is not installed with default settings.
    3. Set the libs.junit.classpath property to point to the correct location of the junit jar files for junit runtime and junit ant task
  4. Run the glassfish (optional)  only required for the integration-test and install phases of the project builds.
  5. Execute ant targets using  "ant -lib "path/to/junit/jars" <target>" to build and test the component.  -lib option is required as the junit ant task can not load the junit runtime jars from the taskdef classpath if the junit taskdef jar is in the lib directory of the ant home.
the following are the ant targets available for execution

Ant build targets to build project using Apache Ant
cd my-first-se
ant -p
Buildfile: build.xml
This project compile, package and manage JBI Components using Ant and JBI Ant tasks in OpenESB2.0
Main targets:

clean clean up
compile compiles jbi component source
compile-test compile the test source
install compile, package, install and starts the jbi component
integration-test run integration tests on the jbi component
package compile and packages jbi component sources into installer zip archive file
run compile, package and installs the jbi component
show displays runtime state of jbi component info
test run unit tests on the jbi component
uninstall Stop, shuts down and uninstalls the jbi component
Default target: run


Posted at 11:14AM Apr 20, 2007 by Srinivasan Chikkala in OpenESB  |  Comments[8]

Comments:

Hi thanks for the post. I would like to test your archetype but I can not get them from the given maven repository.
Tanks
Andrea

Posted by Andrea on February 04, 2008 at 10:55 AM PST #

download.java.net is down currently. Some one is working on this outage. Please use the archetype when the download.java.net comes up or if you are familiar with the https://open-jbi-components.dev.java.net/ source repository, you can build the archetypes on your path and use them. The source code for the archetypes is checked in to open-jbi-components/maven-archetypes-jbi/

Posted by chikkala on February 04, 2008 at 11:33 AM PST #

Hello Chikkala,

I have been using the NetBeans templates to create the JBI BCs. Though the templates provide means to create the NetBeans plug-ins for the newly created BCs, I am quite confused about its usage and the way the WSDL (based configuration) and runtime data is made available to the BC.
Is there a documentation on the design and perhaps a howto? I located one howto about creating the plugin using netbeans, though it was well written, it wasnt useful to me.

Thanks

Cheers
G

Posted by Gautham Kasinath on February 14, 2008 at 03:58 PM PST #

Hi Goutham,

What specific questions you have? Are you trying to understand how to develop the netbeans plugin that will help you add the wsdl extension elements corresponding to your bc to the wsdl document? or are you trying to understand the role of wsdl extensions in the wsdl document itself and how the bc during runtime uses them for the service configuration purpose? There is some documentation at http://wiki.netbeans.org/WSDLEditor regarding netbeans plugin development for bc. We can add more howtos to that if you have specific questions on plugin development.

Posted by chikkala on February 15, 2008 at 01:42 PM PST #

Hiya,
Just getting into jbi and found your explanations the best so far. I have had many "Ah!" moments while reading your examples. Thanks. But I do have one question. Maven. I've just started using it and I'm somewhat confused as to how to get your archetypes from the repo. I know the site is up 'cos I can browse to it and grab the jars manually. But when I try your archetype:create command all I get is a failure to locate the resource. Argh! If it's at all possible is there any chance of contacting me offline so I can work this out? Ta muchly.

Posted by Ms Kimberley Scott on April 27, 2008 at 02:04 AM PDT #

Hi Kimberly Scott,

Sure. you can send me email directly and we can work on fixing the issue. You can also ask questions related to open-esb and open-jbi-components at users@open-esb.dev.java.net, dev@open-esb.dev.java.net or dev@open-jbi-components.dev.java.net. They are very active mailing lists.

Regarding your issue on getting archetype from maven, what version of maven2 you are using? you may want to try executing the archetype with maven2 version 2.0.5. If that is not working, you can always install the manually downloaded archetype and start using it or build from source from the open-jbi-components cvs repository. The source code for the archetypes is checked in to open-jbi-components/maven-archetypes-jbi/. Please check https://open-jbi-components.dev.java.net/public/cvs.html on cvsroot info for source code and do cvs checkout open-jbi-components/maven-archetypes-jbi/ for source code.

Posted by chikkala on April 28, 2008 at 10:49 AM PDT #

Hello Chikkala,
I have been using the NetBeans templates to create the JBI BCs.I have some questions hope you can help me.
1.I have finished the implementation of bc.How can I package it into an installable bc ,such an sipbc.jar?
2.When I create maven project for bc in my current directory, such as D:\bc.The directory is empty or have a pom.xml.If have,how should I create that file before create maven project for my bc?
Thanks a lot!

Posted by Amiee on May 07, 2008 at 02:17 AM PDT #

Hi Amiee,

> I have been using the NetBeans templates to create the JBI BCs.I have some questions hope you can help me.
> 1.I have finished the implementation of bc.How can I package it into an installable bc ,such an sipbc.jar?
When you build the netbeans project, your code is packaged into installable zip file and placed in the "dist" directory under your project root. You can use that as your installable archive file for your component. Note that the extension(.zip or .jar) of the installer file does not matter as long as its contents are in a zip file format.
> 2.When I create maven project for bc in my current directory, such as D:\bc.The directory is empty or have a pom.xml.If have,how should I create that file before create maven project for my bc?
I don't know whether you are using the latest Netbeans project template for creating the BC or SE. If you have the latest one, that project template wizard would create maven project files along with the netbeans build files for you that you need to build bc project from maven.

If you want to add maven project files to your existing netbeans project, it is easy to create the maven project files ( pom.xml and other ant build scripts) to call the netbeans project build to build your component from maven. You can look at the pom.xml files generated by the archetypes mentioned in this blog and follow the same technique to call the netbeans ant build targets from maven project or create the project with latest netbeans template and use the maven project files created by it. Feel free to email me if you have further questions.

Posted by chikkala on May 07, 2008 at 12:06 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed