Working with maven and servicemix

Working with maven and servicemix

During my evaluation of servicemix, creating artifacts with maven fucks up. Much commands which must be known or if not, you have to look at servicemix FAQs and so on. So I eased up the use by creating a little shell script which allows me to create project directorys, ServiceUnits and ServiceAssemblies. To use the script you need Maven2.x (I’ve used version 2.0.8) because the script encapsulates all maven commands which are needed to do create the named units. So here it is:

  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
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
#
# @Copyright Steffen Rumpf <srumpf@brockhaus-gruppe.de
# @Since Fr, 14.03.2008
# @ServiceMix Version 3.2.1
#
# Script for creating working directories and SA/SU- sceletons for servicemix
# This script depends on marven, so 'mvn' runnable must be present
#
#####################################################################################

#### Start Configuration ####
blnUsingJboss=false
jbossDeployDir=deploy
servicemixDeployDir=hotdeploy
#### End Configuration ####



cd $PWD;

clear
echo 
echo "Now working in: $PWD";
echo "";
echo "Note: All commands should be use from root working directory!"
echo "";
if [ "$SERVICEMIX_HOME" == "" ]
then
	echo "SERVICEMIX_HOME is not set! Exiting!"
	exit 1
fi

if [ $1 ]
then
	if [ $1 == "-wd" ]
	then
		echo "#################################"
		echo "# Initalising Working Directory #"
		echo "#################################"
		echo ""
		touch pom.xml
		read -p "GroupID: " groupid
		echo ""
		read -p "Version: " version
		echo ""
		read -p "Name: " name
		echo ""
		read -p "Url: " url
		echo ""
		pom="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n\t<modelVersion>4.0.0</modelVersion>\n\t<groupId>$groupid</groupId>\n\t<artifactId>parent</artifactId>\n\t<version>$version</version>\n\t<packaging>pom</packaging>\n\t<name>$name</name>\n\t<url>$url</url>\n</project>"

		echo -e $pom > pom.xml
		exit 0;
	fi
	if [ $1 == "-su" ]
	then
		echo "#########################"
		echo "# Creating Service Unit #"
		echo "#########################"
		echo ""
		read -p "GroupID: " groupid
		echo ""
		read -p "ArtifactID: " artifactid
		echo ""
		read -p "Version: " version
		echo ""
		
		j=0;
		echo "Choose servicemix archetype:"
		echo "----------------------------"
		for i in service-unit http-consumer http-provider jms-consumer jms-provider ftp-poller ftp-sender jsr181-annotated jsr181-wsdl-first saxon-xquery saxon-xslt eip lwcontainer bean ode camel cxf-se cxf-bc
		do 
			echo "$j: $i"
			j=`expr $j + 1`
		done
		read -p "Please enter a id from above: " archetype

		case $archetype in
			0)archetypeArtifactId='servicemix-service-unit';;
			1)archetypeArtifactId='servicemix-http-consumer-service-unit';;
			2)archetypeArtifactId='servicemix-http-provider-service-unit';;
			3)archetypeArtifactId='servicemix-jms-consumer-service-unit';;
			4)archetypeArtifactId='servicemix-jms-provider-service-unit';;
			5)archetypeArtifactId='servicemix-ftp-poller-service-unit';;
			6)archetypeArtifactId='servicemix-ftp-sender-service-unit';;
			7)archetypeArtifactId='servicemix-jsr181-annotated-service-unit';;
			8)archetypeArtifactId='servicemix-jsr181-wsdl-first-service-unit';;
			9)archetypeArtifactId='servicemix-saxon-xquery-service-unit';;
			10)archetypeArtifactId='servicemix-saxon-xslt-service-unit';;
			11)archetypeArtifactId='servicemix-eip-service-unit';;
			12)archetypeArtifactId='servicemix-lwcontainer-service-unit';;
			13)archetypeArtifactId='servicemix-bean-service-unit';;
			14)archetypeArtifactId='servicemix-ode-service-unit';;
			15)archetypeArtifactId='servicemix-camel-service-unit';;
			16)archetypeArtifactId='servicemix-cxf-se-service-unit';;
			17)archetypeArtifactId='servicemix-cxf-bc-service-unit';;
			*)echo 'Unkown ArtifactID please enter archetypeArtifactId by hand.'
			echo "Please enter a ID from above:"
			read archetypeArtifactId;
			echo ""
			;;
		esac

		mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=$archetypeArtifactId -DgroupId=$groupid -DartifactId=$artifactid -Dversion=$version
		exit 0;
	fi
	if [ $1 == "-sa" ]
	then
		echo "#############################"
		echo "# Creating Service Assembly #"
		echo "#############################"
		echo ""
		read -p "GroupID: " groupid
		echo ""
		read -p "ArtifactID: " artifactid
		echo ""
		read -p "Version: " version
		echo ""
	
		mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly -DgroupId=$groupid -DartifactId=$artifactid -Dversion=$version

		exit 0;
	fi
	if [ $1 == "-dp" ]
	then
		echo "#####################################"
		echo "# Deploying Project into ServiceMix #"
		echo "#####################################"
		echo ""
		read -p "Should maven run first (mvn clean install)? [yes/no]: " runmvn
		while [ "$runmvn" != "yes" -a "$runmvn" != "no" ]
		do
			read -p "Plz type yes or no! " runmvn
		done
		if [ $runmvn == "yes" ]
		then
			mvn clean install
			echo "mvn finished with status: $?"
			echo ""
			if [ $? != 0 ] 
			then
				exit 0
			fi
		fi
		echo ""
		echo "Please enter your SA directory"
		read -p "$PWD must not be given: " sadir

		if [ "$blnUsingJboss" == "true" ] 
		then
			cp $PWD/$sadir/target/*.jar $SERVICEMIX_HOME/$jbossDeployDir
		else
			cp $PWD/$sadir/target/*.jar $SERVICEMIX_HOME/$servicemixDeployDir
		fi

		exit 0;
	fi
fi

echo "Usage:"
echo "-wd	creates a new working directory"
echo "-su	creates a new service unit"
echo "-sa	creates a new service assembly"
echo "-dp	deploy the current project"
echo "-h	shows this help"

There is also a tool available for workin with ServiceMix its called Cimero2 (its a plugin for Eclipse) but its in beta status and will hopefully be maintained and extended in the next time. For this plugin I’ve created some of the BindingComponents which should be used within ServiceMix here you can get them: