| Create a simple JavaEE application with XFire | ||||
|
|
This is simple step by step tutorial on how to build an application that will display content on web pages. Everything will be done in a pedagogic simple way.The nuild is done with the Apache Maven framework instead of ant. Below is a small list of tools used. All fancy words or strange settings will be omitted. In 90% of the applications you build you can use the default settings and they will work. This tutorial contains these parts;
Tools used
Tutorial One, create a web service project with XFire This tutorial will show how you can create an application with XFire from Codehouse. It will not access the database and it will have hardwired properties.Note that today most people use the JAX-WS API directly in the Java EE and do not use aweb service framework at all. Step 1. Create project
Step 2. Create pom files in each folder In the top folder book add this pom file whichjust define some aspects of the project. Note that there is probably as many ways as there are developers out there when it comes to writing pom files. As you can see I have already added the MySql to the pom because I know I will need it later.In the bookjar folder add this pom file. Step 3. Create files needed for the build Now you are almost done. First, before you can build the application you must have directory structure. The jar project shall have this structure;
The war project must have this structure;
It is very important to understand that Maven will not be able to build the application without a web.xml file in the WEB-INF directory. This is just a simple plain one. If maven do not find the dependency jars you must install them into your repository. Note. Sometimes it can be a bit confusing or some overhead to get Maven to work. For instance you might need jar files which do not exist in the maven repository. These will have to be installed manually. Do not give up, it is worth the extra job. After that you will notice how much easier it is to run the build process.
Write eclipse:eclipse and import the projects into Eclipse. We will create 3 java files.
One is our domain object (book), this is what the site is about, books. Since it is so small we use the same object from the database out to our jsp pages.This is one strategy, the other is to convert the objects before displaying them.Two is the service. Put all these objects in the jar project. Thus when you are done in the jar project you shall have these files;
Step 5. Create XFire service file and modify web.xml You will need to add the XFire services.xml file to the META-INF directory. When you are done in the war project it shall look like this.
Step 6. The service.xml file content The file might look like this. One strange thing occurd to me, and is is also written about it on codehaus. I got a file not found error. I followed this instruction and got it to work. Step 7. The domain object (Book.java) Let's assume the book class just contain an author and a title. It might look like this then. Pls. ignore the obious bad programming regarding null pointers and whatsoever. This is a pojo. package se.aja.xfire.Book; import java.io.Serializable; public class Book implements Serializable{ Step 8. The service definition (BookService.java) BookService.java - Our service interface, remember S(ervice)OA. public interface BookService extends Serializable { Step 9. The service implementation (BookServiceImpl.java) BookServiceImpl.java - Our class implementing the interface. public class BookServiceImpl implements BookService { Step 10. Configure the web.xml file to handle XFire
Your web.xml file should look like this now. Step 11. Fix context root for Sun Application Server Your application will default to the name of the war, i.e. war-1.0.0. If you want to define a context name do like this. Add sun-web.xml file to the WEB-INF directory and add this code there <?xml version="1.0" encoding="UTF-8"?> if running on a Sun Application Server or add a jboss-web.xml into the Step 12. Fix context root for JBoss Application Server Your application will default to the name of the war, i.e. war-1.0.0. If you want to define a context name do like this. Add jboss-web.xml file to the WEB-INF directory and add this code there; <jboss-web> <context-root>book</context-root> </jboss-web> Step 13. Deploy the application Type, That is what the default context name should be.If you are unsure and wants to define context. Your first xfire app is working. Test the methods with SOAP UI. Take a break. Drink a coke or a coffee. Step 14. What's left Well most obviously we lack the functionality to access things in the database. The Book file is hardwired with some data. That
|
| Last Updated ( Friday, 27 February 2009 06:54 ) |


