Emil Genov bio photo

Emil Genov

Software developer living in Barcelona

LinkedIn Github Stackoverflow

Project structure and contents

Template project is attached to this page, feel free to use it and update it.

As all Java WS are deployed as WAR file, at some point your project must create one. Here some guidelines how to have a one that works:

  • In WEB-INF/web.xml file, XFireSpring servlet is instantiated. For it's parameter contextConfigLocation, we specify spring config file that will be discussed in next step. Mappings are usual one, this file is same as the one used for working of Spring with XFire:
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"


    <param-name>contextConfigLocation</param-name> (1)

    <servlet-name>XFireServlet</servlet-name> (2)
    <display-name>XFire Servlet</display-name>

    <servlet-name>XFireServlet</servlet-name> (3)


    org.springframework.web.context.ContextLoaderListener (4)


    • (1) Defines that file xfire-servlet.xml, will be automatically available to Spring. Will define this in next section.
    • (2) Define XFireServlet
    • (3) Map it to XXX/services/... path, where XXX will be WAR name
    • (4) Add context listener, so Spring will auto-load xfire-servlet.xml file, see Spring documentation for more detail

  • Create spring config file (I have named it xfire-servlet.xml) for configuring XFire services. Put it in classpath.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <bean id="jaxbServiceFactory" class="org.codehaus.xfire.jaxb2.JaxbServiceFactory" /> (1)
    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /> (2)
    <import resource="classpath:webservices.xml" /> (3)

    • (1) Defines JaxbFactory that will be used by all service exporters
    • (2) Includes XFire internal (in xfire.jar) spring configuration
    • (3) Includes our spring configuration file, in which we will define our exporter/implementation class pairs, for each WS we want to build. This is discussed in next paragraph.

  • Create spring config file (webservice.xml) for instantiation of service implementations and exporters:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <bean id="XFireContractFirst" class="org.example.xfirecontractfirst.XfireContractFirstImpl" /> (1)
    <bean name="XFireContractFirstService" class="org.codehaus.xfire.spring.ServiceBean"> (2)
    <property name="serviceBean" ref="XFireContractFirst" />
    <property name="serviceClass" value="org.example.xfirecontractfirst.XfireContractFirst" /> (3)
    <property name="serviceFactory"><ref bean="jaxbServiceFactory"/></property> (4)

    • (1) This is instantiation of WS implementation class
    • (2) This is instantiation of exporter
    • (3) Which has parameters of implementation bean and service interface
    • (4) Must use JAXB2 binding in order to have interoperability with .Net clients

  • In lib folder You should have following jars:

    • xfire-all-1.2.4.jar
    • xfire-jsr181-api-1.0-M1.jar
    • activation.jar
    • commons-logging-1.0.4.jar
    • mail-1.4.jar
    • jdom-1.0.jar
    • stax-api-1.0.1.jar
    • wsdl4j-1.5.2.jar
    • wstx-asl-3.0.1.jar
    • log4j-1.2.8.jar
    • spring.jar
    • XmlSchema-1.1.jar
    • jaxb-api-2.0.jar
    • jaxb-impl-2.0.1.jar
    • jaxb-xjc-2.0.1.jar (only for generation of java classes from WSDL, not needed to be in WAR file, after that)

  • If you gonna run under Java 1.4, make sure to remove annotations that wsgen have putted in java code generated from WSDL. Also remove xfire-jsr181-api-1.0-M1.jar from classpath.
  • For creating WAR this ant code fragment could be used:
    <war warfile="webservice.war" webxml="webcontent/web.xml">
    <zipfileset dir="lib" prefix="WEB-INF/lib" />
    <zipfileset dir="bin" prefix="WEB-INF/classes"/>


Adding a new WS

Once you have all this plumbing code set in place, adding a new WS is just a song:

  • Just create interface and implentation of service
  • Create implementation and exporter beans in webservices.xml file


Example project

All this can be seen in attached example ws project. Just unpack it, add needed libs (see for list up) from current (version >= 1.2.4) XFire distribution, and run ant which will

create WS implementation classes from WSDL, compile them and generates WAR file. Deploy this file to Application server and test deployed WS.