Axis2M simplify axis2 web service development workload with the help of Maven build tool .Also axis2m promote usage of standard j2ee web application project layout for axis2 development this will enable lot of facilities that available for normal j2ee development to use through maven such as WAR packaging , embedded Jetty etc.
Basically axis2M provide following two artifacts to simplify axis2 development.
Step -1 It is assumed that you have installed Maven2 and configured for your environment. Open a console window and run following command.
mvn archetype:generate -DarchetypeCatalog=http://axis2m.sourceforge.net/repo/
This will show you a wizard to select the number corresponding to "axis2m quickstart" as shown in below.
D:\java\IDE\eclipse\MyWorks\axis2m>mvn archetype:generate -DarchetypeCatalog=http://axis2m.sourceforge.net/repo/ [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate] [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: http://axis2m.sourceforge.net/repo/ -> quickstart (axis2M archetype for creating a web Service application with AXIS2) Choose a number: (1):
Note:
if you get any error message during this phase please refer "installation and troubleshooting "to overcome the problem.Provide following values for wizard
Choose a number: (1): 1 Define value for groupId: : sample Define value for artifactId: : quickstart Define value for version: 1.0-SNAPSHOT: : 1.0
Press enter key for other inputs to take default values.
If you follow all these steps you can see the success message as below
Choose archetype: 1: http://axis2m.sourceforge.net/repo/ -> quickstart (axis2M archetype for creating a web Service application with AXIS2) Choose a number: (1): 1 Define value for groupId: : sample Define value for artifactId: : quickstart Define value for version: 1.0-SNAPSHOT: : 1.0 Define value for package: sample: : Confirm properties configuration: groupId: sample artifactId: quickstart version: 1.0 package: sample Y: : [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating OldArchetype: quickstart:1.0.0 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: sample [INFO] Parameter: packageName, Value: sample [INFO] Parameter: basedir, Value: D:\java\IDE\eclipse\MyWorks\axis2m [INFO] Parameter: package, Value: sample [INFO] Parameter: version, Value: 1.0 [INFO] Parameter: artifactId, Value: quickstart [INFO] ********************* End of debug info from resources from generated POM *********************** [INFO] OldArchetype created in dir: D:\java\IDE\eclipse\MyWorks\axis2m\quickstart [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
Step -2
Now you can import newly created maven project in to your favirioute IDE, in eclipse you can see a new project is created with maven j2ee web application directory structure as below.
In src/main/java/ simpleserver directory Java you can see a single class called .java this is your POJO class that will be exposed as your first web services.
The second important thing is the service.xml file; you can see service.xml (in) src/main /web-main/MET-INF /servces / directory. The exact reason to use this path is, this will enable you to deploy your service as either Axis2 AAR format or WAR java web app package.
Step 3
Now you have your first web services project, you can deploy it either of the following ways
mvn jetty:run
Now open a browser window and type following url to see WSDL definition for your first service.
http://localhost:8080/axis2/services/SimpleService?wsdl
mvn axis2m:run
Now open window and as usually type the following URL and you can see the default screen of simple HTTp server with the service you just created.
http://localhost:8080/axis2/services/SimpleService?wsdl
Again you can follow one of following method to test your service.
You can create a new Maven project for client either using your IDE or arctype;genarte plug in or you can reuse the same project you crated . To generate stub code run the following maven command mvn axis2m:wsdl2java
Here you don't want to specify -uri for WSdl because this is preconfigured to pick up url of our quick start service. For other cases you need to tell your service the wsdl URL explicitly to generate stub.
D:\java\IDE\eclipse\MyWorks\axis2m\quickstart>mvn axis2m:wsdl2java D:\java\IDE\eclipse\MyWorks\axis2m\quickstart>set MAVEN_OPTS=-Xmx512m [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'axis2m'. [INFO] org.apache.maven.plugins: checking for updates from axis2m [INFO] ------------------------------------------------------------------------ [INFO] Building A custom project [INFO] task-segment: [axis2m:wsdl2java] [INFO] ------------------------------------------------------------------------ Downloading: http://repo1.maven.org/maven2/woodstox/wstx-asl/3.0.1/wstx-asl-3.0.1.pom [INFO] [axis2m:wsdl2java] Retrieving document at 'http://localhost:8080/axis2/services/SimpleService?wsdl'. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
Now create the following class called Client.
public class Client { public static void main(String[] args) { try { SimpleServiceStub stub = new SimpleServiceStub(); HelloService req = new HelloService(); req.setMsg(" AxIS2 users"); HelloServiceResponse res = stub.helloService(req); System.out.println(res.get_return()); } catch (AxisFault e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
Now you can run this class on your IDE and see the result of you first web severe invocation.
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService). log4j:WARN Please initialize the log4j system properly. Hello AxIS2 users
You already deploy your service and tested with client too, but you may need to deploy it on a application server. Again you have two options
mvn axis2:aar
In the target directory you can see simplService.aar package.
mvn package
You can see simplesErce.war in target directory. You can deploy this simple.war in any java web application server just like you deploy any other web applications.