There are many resources on the Net giving how to write an Axis2 service. And of course internals of Axis2 itself. This is a simple guide that aims to provide info on howto setup the build environment so that you can get a deployable artifact of an Axis2 service.
- For the most part you’ll be starting after generating Java code against a given WSDL. Generate code with the same version of Axis2 that you’ll be using to deploy this service. Evil things will happen otherwise.
- After this, you can create a skeleton maven project using the maven quickstart archetype.
$ mvn archetype:generate -DgroupId=com.example.myproject -DartifactId=mysuper-service -DpackageName=org.example.myproject -Dversion=1.0-SNAPSHOT
In the next screen you just have to press enter the selected archetype is the quickstart archetype. Then you can select an appropriate version number for the project followed by the package name. Now you should have a skeleton maven project where you can run
mvn clean installand it’ll successfully build it. - Now you can copy the generated classes to mysuper-service/src/main/java and start developing your services.
- To generate an Axis2
.aarfile you have to tell maven to build a.aarfile using the maven aar plugin.<build> <plugins> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-aar-maven-plugin</artifactId> <version>1.4</version> <extensions>true</extensions> <configuration> <servicesXmlFile>${basedir}/resources/services.xml</servicesXmlFile> <wsdlFile>${basedir}/resources/test.wsdl</wsdlFile> <fileSets> <fileSet> <directory>${basedir}/lib</directory> <outputDirectory>lib</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </configuration> </plugin> </plugins> </build>Here, I’ve included a lib folder as well, which contains 3rd party
.jarfiles that’s not available on a maven repo. Once you’ve added the lib folder containing a set of.jarfiles you can add the dependency later using something like,<dependency> <groupId>com.example.myjar</groupId> <artifactId>jarfile</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/the-other-awesome-project.jar</systemPath> </dependency>When you’re specifying a 3rd party JAR dependency even though the actual JAR file might not contain a version number, you have to include something in the
<version>element. Otherwise maven will not work correctly.
Now, when you type $ mvn clean install you should have a .aar file in the target folder. You can upload this to Axis2 and your services will be deployed in a few seconds.
Building within the IDE
An IntelliJ IDEA project file for your project can be easily generated with $ mvn idea:idea. But if you project use maven, you have to install IntelliJ IDEA maven 2 integration plugin. This can be done using the IDEA plugin browser. Even after adding my root pom.xml to Maven-2 Build in IDEA, I was only able to compile all the classes. I couldn’t get any maven plugin goals to be executed. So, Ctrl+F9 still doesn’t generate the .aar file.
As it turns out, you need to install Maven Reloaded plugin to be able to execute maven plugin goals. After installing this, the execution process dies with exit status 1 without any helpful remarks.