Apache Tuscany : Part 2 -Hello World using Eclipse and Maven
This is the second article in series “ Apache Tuscany” which introduces you to the open source SCA framework Apache tuscany. This post talks about hello world with Apache Tuscany.
###Prerequisites
- Eclipse 3.4 or above
- Maven Eclipse Plug in
- Apache tuscany Eclipse plugin
- Java 1.6
###Installing Tuscany distribution
-
Download Apache tuscany 2.0-M5 from the following link
-
Untar(zip) the downloaded tuscany distribution to a directory location. We will refer this location as TUSCANY_HOME
###Creating a Maven Project in Eclipse
- Goto File->New->Other
- Select Maven project and press Next
- Just keep default setttings and press Next
- tuscany-contribution-jar as Artifact and press Next
Enter following details
Group id : com.demo
Artifact Id : sca
Package : com.demo.sca
Press Finish . Now you can see a maven project in your eclipse workspace
Source code
####1.Interface
The project creates a interface called as HelloWorldService . This interface is just a java interface having @Remotable annotation. This annotation is used to make interface a remotable interface .
#####2.Implementation Class
HelloWorldImpl class implements the remotable interface . It uses @Scope(“COMPOSITE”) which says this class (or component) will act as the composite service provider.
####3. Composite File
In resource folder , a HelloWorld.composite file will be created. This file will define the configuration for the compositions. Replace the code in HelloWorld.composite by below code.
This creates a Web service at URL http://localhost:8080/HelloWorld
Note that the service name should be as same as the Interface Name
####4.Contribution file
In META-INF , there is a file filed name sca-contribution.xml .It used to specify which component will be used as launching component. Replace the code by below code
####5.Building the project
Right click on the project and select Run as >Maven Install . It will create a jar file containing the classes of the project.
####6.Running the project
In this example , we will run the project outside of eclipse . Copy the helloworld.jar to $TUSCANY_HOME/bin
- In windows
cd $TUSCANY_HOME /bin(replace by actual path)
./tuscany.bat helloworld.jar
- In linux
$ cd $TUSCANY_HOME/bin ( (replace by actual path)
$./tuscany.sh helloworld.jar
If there are no errors, tuscany will create a web service at http://localhost:8080/HelloWorld