Axis Web Service exception: No compiler found in your classpath! (you may need to add ‘tools.jar’)


If you get an exception like the following one

No compiler found in your classpath! (you may need to add ‘tools.jar’)

when you run the following url

http://localhost:8080/axis/EchoHeaders.jws?method=list

for testing Axis Default application

You need to put tools.jar(%JAVA_HOME%\lib\tools.jar) file inside %CATALINA_HOME(Apache Tomcat Home Location)%\common\lib folder

and restart the Tomcat Application Server

and you will get a result such as the following;

  <?xml version=”1.0″ encoding=”UTF-8″ ?>
 <soapenv:Body>
<listResponse soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/“>
 <listReturn soapenc:arrayType=”soapenc:string[8]” xsi:type=”soapenc:Array” xmlns:soapenc=”http://schemas.xmlsoap.org/soap/encoding/“>
  <listReturn xsi:type=”soapenc:string“>accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*</listReturn>
  <listReturn xsi:type=”soapenc:string“>accept-language:en-us</listReturn>
  <listReturn xsi:type=”soapenc:string“>ua-cpu:x86</listReturn>
  <listReturn xsi:type=”soapenc:string“>accept-encoding:gzip, deflate</listReturn>
  <listReturn xsi:type=”soapenc:string“>user-agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)</listReturn>
  <listReturn xsi:type=”soapenc:string“>host:……</listReturn>
  <listReturn xsi:type=”soapenc:string“>connection:Keep-Alive</listReturn>
  <listReturn xsi:type=”soapenc:string“>cookie:JSESSIONID=…….</listReturn>
  </listReturn>
  </listResponse>
  </soapenv:Body>
  </soapenv:Envelope>

How to use h:selectBooleanCheckbox, h:selectManyCheckbox, h:selectOneRadio JSF 2.0 example


      Click here to attend Spring Framework 4.x and certification course with a discount

Use the following example project for using
h:selectBooleanCheckbox,
h:selectManyCheckbox,
h:selectOneRadio

tags inside a JSF project

<?xml version=’1.0′ encoding=’UTF-8′ ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221;
      xmlns:h=”http://java.sun.com/jsf/html&#8221;
      xmlns:f=”http://java.sun.com/jsf/core”&gt;
    <h:head>
        <title>h:selectBooleanCheckbox – h:selectManyCheckbox – h:selectOneRadio example</title>
    </h:head>
    <h:body style=”background-color: lightskyblue”>
        <h1>h:selectBooleanCheckbox <br></br>
            h:selectManyCheckbox <br></br>
            h:selectOneRadio example JSF 2.0 project</h1>
        <h:form>            
            <h2>h:selectBooleanCheckbox example</h2>
            <h:selectBooleanCheckbox id=”checkboxApproval” value=”#{ContentGenerator.selectedValueBooleanCheckbox}”/>
            <h:outputText value=”#{ContentGenerator.checkboxApprovalText}”/>    
            <h2>h:selectManyCheckbox example</h2>
            <h:selectManyCheckbox id=”manyCheckBoxes”  value=”#{ContentGenerator.selectedItemsManyCheckBox}” >
                <f:selectItems value=”#{ContentGenerator.checkBoxes}” />
            </h:selectManyCheckbox>           
            <h2>h:selectOneRadio example</h2>
            <h:selectOneRadio id=”selectOneRadio” value=”#{ContentGenerator.selectedItemValueSelectOneRadio}”>
                <f:selectItems value=”#{ContentGenerator.radios}” />
            </h:selectOneRadio>           
            <h:commandButton action=”#{ContentGenerator.calledByHtmlJSFCommanButton}” value=”Produce ouput” />           
            <h:panelGroup rendered=”#{ContentGenerator.renderOutput}”>
                <br></br>
                <br></br>
                h:selectBooleanCheckbox — I understand is selected –>
                <b><h:outputText value=”#{ContentGenerator.selectedValueBooleanCheckbox}” /></b>
                <br></br>
                <br></br>
                h:selectManyCheckbox — selected values –>
                <b><h:outputText value=”#{ContentGenerator.selectedItemValuesManyCheckBox}” /></b>
                <br></br>
                <br></br>
                h:selectOneRadio — selected value –>
                <b><h:outputText value=”#{ContentGenerator.selectedItemValueSelectOneRadio}” /></b>
            </h:panelGroup>            
        </h:form>
    </h:body>
</html>

Source code for generating content for h:selectManyCheckbox and h:selectOneRadio JSF components

package tagscontentgenerator;

import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

/**
 *
 * @author tunatore
 */
@ManagedBean(name=”ContentGenerator”)
@RequestScoped
public class ContentGenerator {

    /** Creates a new instance of ContentGenerator */
    private boolean renderOutput = false;
    private boolean selectedValueBooleanCheckbox = false;

    private String selectedItemValuesManyCheckBox = “”;
    private String selectedItemValueSelectOneRadio = “”;
    private String checkboxApprovalText = “I understand!”;  

    private List<String> selectedItemsManyCheckBox = null;
    private List<SelectItem> checkBoxes = null;
    private List<SelectItem> radios = null;

public ContentGenerator() {

        checkBoxes = new ArrayList<SelectItem>();       
        SelectItem item1 = new SelectItem(“Subaru”, “Subaru”);
        SelectItem item2 = new SelectItem(“Honda”, “Honda”);
        SelectItem item3 = new SelectItem(“Toyota”, “Toyota”);
        SelectItem item4 = new SelectItem(“Ford”, “Ford”);
        checkBoxes.add(item1);
        checkBoxes.add(item2);
        checkBoxes.add(item3);
        checkBoxes.add(item4);

        radios = new ArrayList<SelectItem>();
        SelectItem item5 = new SelectItem(“Car”, “Car”);
        SelectItem item6 = new SelectItem(“Plane”, “Plane”);
        SelectItem item7 = new SelectItem(“Ship”, “Ship”);
        radios.add(item5);
        radios.add(item6);
        radios.add(item7);

}

    /**
     * @return the checkboxApprovalText
     */
public String getCheckboxApprovalText() {
return checkboxApprovalText;
}

/**
     * @param checkboxApprovalText the checkboxApprovalText to set
     */
public void setCheckboxApprovalText(String checkboxApprovalText) {
this.checkboxApprovalText = checkboxApprovalText;
}

    /**
     * @return the checkBoxes
     */
public List<SelectItem> getCheckBoxes() {
return checkBoxes;
}

   /**
     * @return the renderOutput
     */
public boolean isRenderOutput() {
return renderOutput;
}

    /**
     * @param renderOutput the renderOutput to set
     */
public void setRenderOutput(boolean renderOutput) {
this.renderOutput = renderOutput;
}

  /**
     * @param checkBoxes the checkBoxes to set
     */
public void setCheckBoxes(List<SelectItem> checkBoxes) {
this.setCheckBoxes(checkBoxes);
}

    /**
     * @return the radios
     */
public List<SelectItem> getRadios() {
return radios;
}

    /**
     * @param radios the radios to set
     */
public void setRadios(List<SelectItem> radios) {
this.radios = radios;
}

    /**
     * @return the selectedItemValues
     */
public String getSelectedItemValuesManyCheckBox() {
return selectedItemValuesManyCheckBox;
}

   /**
     * @param selectedItemValues the selectedItemValues to set
     */
public void setSelectedItemValuesManyCheckBox(String selectedItemValues) {
this.selectedItemValuesManyCheckBox = selectedItemValues;
}

/**
* @return the selectedItemValuesSelectOneRadio
*/
public String getSelectedItemValueSelectOneRadio() {
return selectedItemValueSelectOneRadio;
}

    /**
     * @param selectedItemValuesSelectOneRadio the selectedItemValuesSelectOneRadio to set
     */
public void setSelectedItemValueSelectOneRadio(String selectedItemValueSelectOneRadio) {
this.selectedItemValueSelectOneRadio = selectedItemValueSelectOneRadio;
}

    /**
     * @param selectedItemsManyCheckBox the selectedItemsManyCheckBox to set
     */
public void setSelectedItemsManyCheckBox(List<String> selectedItemsManyCheckBox) {
this.selectedItemsManyCheckBox = selectedItemsManyCheckBox;
}

    /**
     * @return the selectedValueBooleanCheckbox
     */
public boolean isSelectedValueBooleanCheckbox() {
return selectedValueBooleanCheckbox;
}

/**
     * @param selectedValueBooleanCheckbox the selectedValueBooleanCheckbox to set
     */
public void setSelectedValueBooleanCheckbox(boolean selectedValueBooleanCheckbox) {
this.selectedValueBooleanCheckbox = selectedValueBooleanCheckbox;
}

public void calledByHtmlJSFCommanButton() {
this.renderOutput = true;
}

    /**
     * @return the selectedItemsManyCheckBox
     */
    public List<String> getSelectedItemsManyCheckBox() {

        if(selectedItemsManyCheckBox !=null) {
        for (String selectedItem : selectedItemsManyCheckBox) {
            selectedItemValuesManyCheckBox += selectedItem + ” “;
        }
        }
        return selectedItemsManyCheckBox;
    }
}

Example output;

Download Source

How to use Simple Tag Handlers in J2EE


In J2EE environment tag files use another JSP files for implementing the functionality of tags however tag handlers use Java classes. So that, it is more flexible to use tag handlers if you need to design your own tags in a J2EE Project.

In this post, I am going to explain How to code a Simple Tag Handler with three basic examples including;

  • Simple tag handler without a body
  • Simple tag handler with a body
  • Simple tag with an attribute

First of all, you will need to put the following tld files inside a folder tlds inside WEB-INF folder.

WEB-INF>tlds
–>dateFinderSimpleTags.tld
–>iteratorSimpleTags.tld
–>specificWordReplacerSimpleTags.tld

The content for these files are like below;

dateFinderSimpleTags.tld

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<taglib xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd&#8221;
    version=”2.1″>
<tlib-version>1.0</tlib-version>

    <!– tag lib directive inside a jsp file will use the following name example –>  
    <!– <%@taglib prefix=”customTags” uri=”simpleTagsDateTime”%>–>
    <uri>simpleTagsDateTime</uri>
    <tag>
<description>This tag handler is used for getting server time</description>
        <!–custom tag will use the following name for mapping example <customTags:findDatetime/>–>
        <name>findDateTime</name>
        <tag-class>com.tunatore.simpletaghandlerexample.SimpleTagHandlerDateFinder</tag-class>
        <!– body content for the tag is NOT allowed –>
        <body-content>empty</body-content>
</tag>

</taglib>

iteratorSimpleTags.tld

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<taglib xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd&#8221;
    version=”2.1″>
<tlib-version>1.0</tlib-version>

    <!– tag lib directive inside a jsp file will use the following name example –>  
    <!– <%@taglib prefix=”customTags” uri=”simpleTagsWithIterator”%>–>
    <uri>simpleTagsWithIterator</uri>
    <tag>
        <description>This tag handler is used for replacing a specific word inside a tag body</description>
        <!–custom tag will use the following name for mapping example <customTags:peopleIterator/>–>
        <name>peopleIterator</name>
        <tag-class>com.tunatore.simpletaghandlerexample.SimpleTagHandlerPeopleIterator</tag-class>
        <!– body content for the tag is allowed –>
        <body-content>scriptless</body-content>    
        <!– define an atrribute for the tag like below–>
        <attribute>
            <name>peopleList</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

specificWordReplacerSimpleTags.tld

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<taglib xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd&#8221;
    version=”2.1″>
<tlib-version>1.0</tlib-version>

    <!– tag lib directive inside a jsp file will use the following name example –>  
    <!– <%@taglib prefix=”customTags” uri=”simpleTags”%>–>
    <uri>simpleTagsWordReplacer</uri>
    <tag>
        <description>This tag handler is used for replacing a specific word inside a tag body</description>
        <!–custom tag will use the following name for mapping example <customTags:wordReplacer/>–>
        <name>wordReplacer</name>
<tag-class>com.tunatore.simpletaghandlerexample.SimpleTagHandlerSpecificWordReplacer</tag-class>
        <!– body content for the tag is allowed –>
        <body-content>scriptless</body-content>
</tag>

</taglib>

Next you need to create Java Classes for these Simple Tag Handlers such as the following ones;

SimpleTagHandlerDateFinder .java

package com.tunatore.simpletaghandlerexample;

import java.io.IOException;
import java.util.Calendar;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author tunatore
 */
public class SimpleTagHandlerDateFinder extends SimpleTagSupport{

    @Override
    public void doTag() throws JspException, IOException {       
        //will write the content inside a jsp file
        getJspContext().getOut().print(Calendar.getInstance().getTime().toString());        
    }       
}

SimpleTagHandlerPeopleIterator.java
package com.tunatore.simpletaghandlerexample;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author tunatore
 */
public class SimpleTagHandlerPeopleIterator extends SimpleTagSupport{

    private List peopleList;

    @Override
    public void doTag() throws JspException, IOException {    

        People people1 = new People(“James”,”Gosling”);
        People people2 = new People(“Bill”,”Gates”);
        People people3 = new People(“Tuna”,”Tore”);

        peopleList = new ArrayList();
        peopleList.add(people1);     
        peopleList.add(people2);
        peopleList.add(people3);

        for (Iterator it = peopleList.iterator(); it.hasNext();) {
            People people = (People)it.next();
            getJspContext().setAttribute(“people”, people);
            //null says that the tag handler write its content inside the tag
            //not for another writer
            getJspBody().invoke(null);
        }

    }

    /**
     * @return the peopleList
     */
    public List getPeopleList() {
        return peopleList;
    }

    /**
     * @param peopleList the peopleList to set
     */
    public void setPeopleList(List peopleList) {
        this.peopleList = peopleList;
    }

}

SimpleTagHandlerSpecificWordReplacer.java
package com.tunatore.simpletaghandlerexample;

import java.io.IOException;
import java.io.StringWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author tunatore
 */
public class SimpleTagHandlerSpecificWordReplacer extends SimpleTagSupport{

    @Override
    public void doTag() throws JspException, IOException {    

       StringWriter stringWriter = new StringWriter();
       getJspBody().invoke(stringWriter);
       getJspContext().getOut().print(“Original Text</br>”);
       getJspContext().getOut().print(“</br>##################</br>”);
       getJspContext().getOut().print(stringWriter);
       String replacedContent = stringWriter.getBuffer().toString().replaceAll(“C#”,”Java”);      
       //this will write the content
       getJspContext().getOut().print(“</br>##################</br>”);
       getJspContext().getOut().print(“</br>Replaced Text</br>”);
       getJspContext().getOut().print(“</br>##################</br>”);
       getJspContext().getOut().print(replacedContent);
       getJspContext().getOut().print(“</br>##################</br>”);
    }       
}

And last for the classes create a People class as bean inside the same package

People.java

package com.tunatore.simpletaghandlerexample;

/**
 *
 * @author tunatore
 */
public class People {

    private String name;
    private String surname;

    People(String name, String surname) {    
        this.name = name;
        this.surname = surname;    
    }
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }        

}

For testing custom tags I created 3 basic jsp files such as the following ones;

simpleTagWithIterator.jsp

<%–
    Document   : index
    Created on : 03.June.2011, 16:39:20
    Author     : tunatore
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@taglib prefix=”customTags” uri=”simpleTagsWithIterator”%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
         <title>Simple Tag Handler Body Itetor (People Iterator) Example</title>
    </head>
    <body style=”background-color:lightsteelblue” >
        <h1>People Iterator Example</h1>
        <table border=”1″ width=”400px”>
            <tr><th><b>Name</b></th><th><b>Surname</b></th></tr>
            <customTags:peopleIterator peopleList=”${peopleList}”>
                <tr><td>${people.name}</td><td>${people.surname}</td></tr>
            </customTags:peopleIterator>
        </table>
    </body>
</html>

simpleTagWithaBody.jsp

<%–
    Document   : index
    Created on : 03.June.2011, 16:39:20
    Author     : tunatore
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@taglib prefix=”customTags” uri=”simpleTagsWordReplacer”%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
        <title>Simple Tag Handler With a Body Example</title>
    </head>
    <body style=”background-color:lightsteelblue” >
        <h1>Word Replacer example</h1>
        <b>
          <customTags:wordReplacer>
              We all like C# developers because they are open source advocates!
              C# developers are perfect!
          </customTags:wordReplacer>
        </b>
    </body>
</html>

simpleTagWithoutBody.jsp

<%–
    Document   : index
    Created on : 03.June.2011, 16:39:20
    Author     : tunatore
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@taglib prefix=”customTags” uri=”simpleTagsDateTime”%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
         <title>Simple Tag Handler With a Body Example</title>
    </head>
    <body style=”background-color:lightskyblue” >
        <h1>Get Server Time</h1>
        <b><customTags:findDateTime/></b>
    </body>
</html>

After calling these jsp files results will be same as the following screens;

If you run simpleTagWithoutBody.jsp you will get the following result

If you run simpleTagWithaBody.jsp you will get the following result


If you run simpleTagWithIterator.jsp you will get the following result


Download Project