XDoclet-Building Tools

Java-Examples

                                                                                                                                                                                                                    Show all | Close all
  • Overview

    • What are building tools


      There many Java Build tools available for the Java programmers. These tools help the programmer to build their project efficiently. Build process is repetitive process where programmer builds the project again and again to test the changes in the project code. While developing a project code changes needs to be test and the testing requires the build of the code and finally deploying on the server for testing. Build tools automate the repetitive process and allows the programmer to concentrate on the project development. It also reduces the overall build time. Build tools makes the build process just a single click work. Here are the list of build tools available in Java:

      Types of building tools

      • Ant
      • Maven
      • Xdoclet
    • why we use building tools

      There many Java Build tools available for the Java programmers. These tools help the programmer to build their project efficiently. Build process is repetitive process where programmer builds the project again and again to test the changes in the project code. While developing a project code changes needs to be test and the testing requires the build of the code and finally deploying on the server for testing. Build tools automate the repetitive process and allows the programmer to concentrate on the project development. It also reduces the overall build time. Build tools makes the build process just a single click work. Here are the list of build tools available in Java:
    • Types of Building tools

      What are testing tools ?


      Testing tools are a form of automated testing. It is basically using programs to do different testing tasks i.e. doing the tests through some form of automated method. They are computerized and help in assisting every type of testing. Some of these testing tasks include checking the conditions, also checking the predicted results with the actual results along with many other types of testing involved. A lot of these testing tools have commonly used coding languages such as Java and C. The testing tools themselves have been made using these programming languages. A lot of the tools used have different options available to help with testing. This can be very useful when producing the essential reports of that particular product.

      Different Methodologies Used For Testing


      There are different methodologies that are can be used when implementing testing tools. The testing methodologies can be used together or individually. It all depends on what you are testing as they provide better resources for different tasks. Below are a few of the main different types that are used but there are other types of testing that can be used:

      Unit Testing

      This is the software used for verification and validation. It's a method in which the programmer can test all the separate code and see if it is viable to use. This type of testing is based on a small scale and uses small units of the program. When looking at procedural programming the unit can be any individual function or a procedure which is written in the same language as the production code.

      White Box Testing

      This is also known as clear box testing, glass box testing, translucent box testing or structural testing. It uses the internal perspective of the system and then designs test cases based on this internal structure. Basically the code itself and all the conditions, statements and paths along with it are tested. Programming skills are required for noticing all the paths through the software. White box testing does many things such as analyzing the data flow, control flow, information flow and coding practices.

      Regression Testing

      This is a type of software testing which basically looks for software regressions. The regressions can happen whenever the software stops working as it is meant to. The testing makes sure that any bugs or changes have been fixed which may have caused previous working functions to have failed as a result of the newly added features. It is better to do this type of testing under the automated tool environment. The regression testing may take place once the programmer has tried to fix a problem or has purposely added in code to give out errors.

      Integration Testing

      This is where the separate software modules are put together and are then tested as a whole. This normally takes place after unit testing has been done. The point of doing integration testing is because it verifies the functional and performance requirements of the design items. It is component of Extreme Programming (XP). Two different ways of doing integration testing is bottom-up and top-down.
  • What is XDoclet


    XDoclet is an open source code generation engine. It enables Attribute-Oriented Programming for java. In short, this means that you can add more significance to your code by adding meta data (attributes) to your java sources. This is done in special JavaDoc tags.
    XDoclet will parse your source files and generate many artifacts such as XML descriptors and/or source code from it. These files are generated from templates that use the information provided in the source code and its JavaDoc tags.
    XDoclet lets you apply Continuous Integration in component-oriented development. Developers should concentrate their editing work on only one Java source file per component.
    This approach has several benefits:
    You don't have to worry about out dating deployment meta-data whenever you touch the code. The deployment meta-data is continuously integrated.
    Working with only one file per component gives you a better overview of what you're doing. If your component consists of several files, it's easy to lose track. If you have ever written an Enterprise Java Bean, you know what we mean. A single EJB can typically consists of 7 or more files. With XDoclet you only maintain one of them, and the rest is generated.
    You dramatically reduce development time, and can concentrate on business logic, while XDoclet generates 85% of the code for you.
    Currently XDoclet can only be used as part of the build process utilizing Jakarta Ant.
    Although XDoclet originated as a tool for creating EJBs, it has evolved into a general-purpose code generation engine. XDoclet consists of a core and a constantly growing number of modules. It is fairly straightforward to write new modules if there is a need for a new kind of component.
    XDoclet comes with a set of modules for generation of different kinds of files. Users and contributors can write their own modules (or modify existing ones) if they wish to extend the functionality of XDoclet.
  • Using XDoclet

    Using XDoclet is simple. Just as you write JavaDoc tags for your code (you do comment your code, don't you?), you now add XDoclet tags too. These tags are used by XDoclet as providers of meta-data that is then used to generate other files as required.
    For a thorough example of how to use XDoclet, consult the samples. However, this page should give you enough of a start to XDoclet your code.
    A typical XDoclet comment might look like this:
    /**
     * This is the Account entity bean. It is an example of how to use the
     * EJBDoclet tags.
     *
     * @see Customer
     *
     * @ejb.bean
     *     name="bank/Account"
     *     type="CMP"
     *     jndi-name="ejb/bank/Account"
     *     local-jndi-name="ejb/bank/LocalAccount"
     *     primkey-field="id"
     *
     * @ejb.finder
     *     signature="java.util.Collection findAll()"
     *     unchecked="true"
     *
     * @ejb.transaction
     *     type="Required"
     *
     * @ejb.interface
     *     remote-class="test.interfaces.Account"
     *
     * @ejb.value-object
     *     match="*"
     *
     * @version 1.5
     */
    There are three parts to that comment: The comment, the javadoc tag, and the XDoclet tags. The first two are your standard documentation. Just because you are using XDoclet doesn't mean that you stop doing normal documentation. The third part of the comment is the part that we are interested in. An XDoclet tag is comprised of the following parts:
    @namespace.tag-name attribute-name="attribute value"
    The concept is similar to an XML element, which has a tag name and an optional set of attributes. The difference is the syntax.
    Tags are grouped by namespaces, and have names that are unique within that namespace. Tags can have zero or more attributes, which are grouped in name="value" pairs. Looking at the above example, we find the first tag is in the ejb namespace, and is called bean. The ejb.bean tag defines data relating to Enterprise Java Beans. Every EJB will require a name, and it is specified here. The namespace is a mechanism for making sure no name collision happens. Namespaces include ejb, web, jboss, weblogic, struts and so on. So it's simply a way to group related tags. For details on individual tags, consult the Tag Reference.
    Tag values can be specified as ant properties. For example:
    @jboss.create-table create="${jboss.create.table}"
    Where the jboss.create.table is a property defined in the ant project. For more information on ant properties consult the Jakarta Ant documentation.
    Tags exist at both class and method level (and in some rare cases even on the field or constructor level). As a general rule, if information can be determined by the name or type of a class, then it will be - and hence there will not be a requirement to specify that information with a tag. An example of this is the type attribute of the ejb.bean tag example above. The type in this instance refers to the Entity type (CMP or BMP), but if the class implemented the javax.ejb.SessionBean interface the type would be Stateful or Stateless. So in the above example, the type can be omitted.
    To start using XDoclet you must first determine what it is you wish to use it for. The two most popular usages are EJBDoclet and WebDoclet. Generally you should define the XDoclet task for Ant, setup the configuration parameter. Here is an example:
    <path id="project.class.path">
        <fileset dir="${lib.dir}">
            <include name="*.jar"/>
        </fileset>
    </path>
    
    <target name="ejbdoclet" depends="prepare">
        <taskdef
            name="ejbdoclet"
            classname="xdoclet.modules.ejb.EjbDocletTask"
            classpathref="project.class.path"
        />
    
        <tstamp>
            <format property="TODAY" pattern="d-MM-yy"/>
        </tstamp>
    
        <ejbdoclet
            destdir="${generated.java.dir}"
            excludedtags="@version,@author"
            addedtags="@xdoclet-generated at ${TODAY}"
            ejbspec="2.0"
        >
            <fileset dir="${java.dir}">
                <include name="**/*Bean.java"/>
            </fileset>
    
            <dataobject/>
    
            <packageSubstitution packages="persistence" substituteWith="interfaces"/>
    
            <remoteinterface pattern="{0}Remote"/>
            <localinterface pattern="{0}"/>
    
            <homeinterface />
            <localhomeinterface/>
    
            <entitypk/>
            <entitycmp/>
    
            <deploymentdescriptor destdir="${build.dir}/ejb/META-INF"/>
            <jboss version="3.0"
                securityDomain="java:/jaas/samples"
                preferredRelationMapping="relation-table"
                datasource="java:/DefaultDS"
                datasourcemapping="Hypersonic SQL"
                destdir="${build.dir}/ejb/META-INF"
            />
        </ejbdoclet>
    </target>
    
    <target name="compile" depends="ejbdoclet">
       <!-- Compile EJBs -->
       <javac
           srcdir="${java.dir}:${generated.java.dir}"
           destdir="${build.dir}/ejb"
           includes="test/ejb/*.java, test/interfaces/*.java"
       >
    </target>
    Here the compile target depends on the ejbdoclet target. This means that before compiling anything all home/local/remote interfaces, primary key, data-objects and deployment descriptors are generated. The first thing you have to do is define the ejbdoclet task for Ant.
    To do so you use taskdef, where you specify xdoclet.modules.ejb.EjbDocletTask as the class implementing ejbdoclet task. Note that the classpathref points to the path with id "project.class.path". This path should have all XDoclet jar files and commons-logging.jar.
    Next you declare ejbdoclet task, with a set of configuration parameters and nested elements. For example, destdir specifies where to put generated files. As you can see there's an inheritance mechanisms also, you can override this destdir parameter for each nested element (or as we call it sub-task).
    <deploymentdescriptor/> does exactly that; put the generated ejb-jar.xml file somewhere else than where generated java sources for home/remote/pk/etc are placed. For a complete list of configurable parameters consult the Ant Task Reference for each task and sub-task.
    By default each task has some built-in sub-tasks. Some of them are mandatory, for example <remoteinterface/> and <localinterface/>, can you imagine an EJB without a remote or local (EJB 2.0 only) interface? Some other tasks may be optional, for example <jboss/> is optional if you're not using JBoss Application Server.
    There's even a third form of sub-tasks: <template/>. This is useful for cases where you want to design your own template file and generate a customized file. So, you need a simple way to let XDoclet use your template file. Here is an example:
    <taskdef
        name="templatedoclet"
        classname="xdoclet.DocletTask"
        classpathref="project.class.path"
    />
    
    <templatedoclet
        destdir="${generated.java.dir}"
        excludedtags="@version,@author"
    >
        <fileset dir="${java.dir}">
            <include name="**/*Bean.java"/>
        </fileset>
        <template
            templateFile="/mytemplate.xdt"
            destinationfile="mygeneratedfile.txt"
        />
    </templatedoclet>
    
    So you put a <template/> element in the task, specify the path to your template file and output file name (which will we stored in the directory specified in destdir parameter). This is very useful for those creative people who want to easily take advantage of XDoclet's framework-like capabilities and define their own set of @tags and templates generating something from those @tags.
    So whenever you build, ejbdoclet (and/or whatever other task) is run and generates up-to-date files.
    Quick checklist of things to get XDoclet running:
    • Modify (creating if required) your build.xml script (see Jakarta Ant web site for details).
    • Add XDoclet tags to your source code.
    • Stop worrying about all that boring code you used to write! XDoclet does it all for you now.
    The mailing lists provide a wealth of knowledge, and the developers are lurking on the xdoclet-user list, so feel free to ask questions, make suggestions, or just generally discuss XDoclet.

  • Environment and requirement


    XDoclet will run on any platform where there is a suitable Java 2 runtime environment. You have to make sure tools.jar from JDK's lib directory is on your classpath, and that you are using Jakarta Ant 1.5 or higher (XDoclet does not support previous versions).
    XDoclet has been used successfully on many platforms, including Linux, UNIX, Windows 9x, NT, 2000 and XP, MacOSX.
    Starting from XDoclet 2, JDK 1.4 is required to run (and build) XDoclet. However, the generated sources are still compilable on JDK 1.3 environments.
  • Installation steps for Xdoclet

    Steps to Easy Web Development

    This section will take you through the step-by-step process of web project creation, XDoclet configuration, deployment descriptor generation, and Tomcat 5 deployment.

    1) Create a New Web Project

    1. Change to or open the MyEclipse Perspective (Window > Open Perspecitve > Other... > MyEclipse) .
    2. Select File > New... > Project > J2EE > Web Module Project, then press the Next button.
    3. For the project name use MyXDocletWeb and for the context root specify /MyXDocletWeb, as shown in Figure 1 below, and press the Finish button.  The resulting project structure will be the same as that shown in Figure 2.
      Creating the Web Project
      Figure 1. Creating the Web Project
      Web Project Layout
      Figure 2. Web Project Layout

    2) Create a Servlet

    1. Select the project MyXDocletWeb in the Package Explorer
    2. Select File > New... > Servlet,
    3. Populate it with the package name com.myeclipse.tutorial.servlet and class name BasicServlet as shown in Figure 3, then press the Next button.
      Creating the Servlet
      Figure 3. Creating the Servlet
    4. When the second page of the servlet wizard is displayed, deselect the checkbox labeled Generate/Map web.xml File and select the finish button as shown in Figure 4.  We don't need to have the wizard map the web.xml file since we'll be generating it based on our XDoclet settings later.
      Creating the Servlet - Page 2
      Figure 4. Creating the Servlet - Page 2
    5. After the servlet is generated, it will be opened in the Java editor. Replace the generated source code completely with the following contents and save the file.
    /*
     * BasicServlet.java
     * Created on Aug 7, 2003
     */
    package com.myeclipse.tutorial.servlet;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
     * Basic Servlet Using XDoclet.
     *
     * @author Administrator
     * @version 1.0, Aug 7, 2003
     *
     * @web.servlet name = "BasicServlet"
     *              display-name = "Basic Servlet"
     *              load-on-startup = "1"
     * @web.servlet-init-param name = "hi"
     *                         value = "${basic.servlet.hi}"
     * @web.servlet-init-param name = "bye"
     *                         value = "${basic.servlet.bye}"
     * @web.servlet-mapping url-pattern = "/Basic/*"
     * @web.servlet-mapping url-pattern = "*.Basic"
     * @web.servlet-mapping url-pattern = "/BasicServlet"
     * @web.resource-ref description = "JDBC resource"
     *                   name = "jdbc/mydb"
     *                   type = "javax.sql.DataSource"
     *                   auth = "Container"
     */
    public class BasicServlet extends HttpServlet {
        /**
         * Constructor of the object.
         */
        public BasicServlet() {
            super();
        }

        /**
         * Destruction of the servlet.
         */
        public void destroy() {
            super.destroy(); // Just puts "destroy" string in log
        }

        /**
         * The doGet method of the servlet.
         *
         * @param request the request send by the client to the server
         * @param response the response send by the server to the client
         *
         * @throws ServletException if an error occurred
         * @throws IOException if an error occurred
         */
        public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * The doPost method of the servlet.
         *
         * @param request the request send by the client to the server
         * @param response the response send by the server to the client
         *
         * @throws ServletException if an error occurred
         * @throws IOException if an error occurred
         */
        public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * Returns information about the servlet.
         *
         * @return String information about this servlet
         */
        public String getServletInfo() {
            return "Basic Servlet Using XDoclet";
        }

        /**
         * Initialization of the servlet.
         *
         * @throws ServletException if an error occurred
         */
        public void init() throws ServletException {
            // Put your code here
        }

        /**
         * Initialization of the servlet with the servlet's configuration.
         *
         * @param config the servlet's configuration
         *
         * @throws ServletException if an error occurred
         */
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        }

        /**
         * Processes requests for both HTTP GET and POST methods.
         *
         * @param request servlet request
         * @param response servlet response
         *
         * @throws ServletException if an error occurred
         * @throws java.io.IOException if an I/O error occurred
         */
        protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
            ServletConfig config = this.getServletConfig();
            String hi = config.getInitParameter("hi");
            String bye = config.getInitParameter("bye");

            try {
                response.setContentType("text/html");

                PrintWriter out = response.getWriter();
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Basic Servlet</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>hi:  " + hi + "</h1>");
                out.println("<h1>bye:  " + bye + "</h1>");
                out.println("</body>");
                out.println("</html>");
                out.close();
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
    }
    Explanation of XDoclet Tags Used in the Servlet
    The example tag illustrates the use of several helpful XDoclet tags. The tags and what they generate are displayed in the table below.
    XDoclet Tag Generated Code
    @web.servlet name = "BasicServlet"     display-name = "Basic Servlet"     load-on-startup = "1" Generated into the web.xml:

    <servlet>
       <servlet-name>BasicServlet</servlet-name>
       <display-name>Basic Servlet</display-name>
       <servlet-class>com.myeclipse.tutorial.servlet.BasicServlet</servlet-class>
       ...
       <load-on-startup>1</load-on-startup>
    </servlet>
    @web.servlet-init-param name = "hi"
        value = "${basic.servlet.hi}"
    @web.servlet-init-param name = "bye"
        value = "${basic.servlet.bye}"
    Generated into the web.xml when Ant properties are set to: (basic.servlet.hi = Ant is cool!) and (basic.servlet.bye = XDoclet Rocks!):

    <servlet>
       ...
       <init-param>
          <param-name>hi</param-name>
          <param-value>Ant is cool!</param-value>
       </init-param>
       <init-param>
          <param-name>bye</param-name>
          <param-value>XDoclet Rocks!</param-value>
       </init-param>
       ...
    </servlet>
    @web.servlet-mapping url-pattern = "/Basic/*"
    @web.servlet-mapping url-pattern = "*.Basic"
    @web.servlet-mapping url-pattern = "/BasicServlet"
    Generated into web.xml:

    <servlet-mapping>
       <servlet-name>BasicServlet</servlet-name>
       <url-pattern>/Basic/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <servlet-name>BasicServlet</servlet-name>
       <url-pattern>*.Basic</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <servlet-name>BasicServlet</servlet-name>
       <url-pattern>/BasicServlet</url-pattern>
    </servlet-mapping>
    @web.resource-ref
        description = "JDBC resource"
        name = "jdbc/mydb"
        type = "javax.sql.DataSource"
        auth = "Container"
    Generated into web.xml:

    <resource-ref>
       <description>JDBC resource</description>
       <res-ref-name>jdbc/mydb</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
    </resource-ref>

    3) Create a Custom Tag Class

    1. Select the project MyXDocletWeb in the Package Explorer
    2. Select File > New... > Class,
    3. Populate it with the package name com.myeclipse.tutorial.customtag, class name BasicTag, and subclass javax.servlet.jsp.tagext.TagSupport as shown in Figure 5, then press the Finish button.
      Creating a Custom Tag
      Figure 5. Creating a Custom Tag
    4. After the tag is generated, it will be opened in the Java editor. Replace the generated source code completely with the following contents and save the file.
    /*
     * BasicTag.java
     */
    package com.myeclipse.tutorial.customtag;

    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.tagext.TagSupport;

    /**
     * Basic Custom Tag Using XDoclet.
     *
     * @jsp.tag name="BasicTag"
     * @jsp.variable name-given="currentIter"
     *               class="java.lang.Integer"
     *               scope="NESTED"
     *               declare="true"
     * @jsp.variable name-given="atBegin"
     *               class="java.lang.Integer"
     *               scope="AT_BEGIN"
     *               declare="true"
     * @jsp.variable name-given="atEnd"
     *               class="java.lang.Integer"
     *               scope="AT_END"
     *               declare="true"
     *
     */
    public class BasicTag extends TagSupport {
        /** Holds value of property includePage. */
        private boolean includePage = false;

        /** Holds value of property includeBody. */
        private boolean includeBody = false;

        /** Holds value of property iterate. */
        private int iterate = 0;

        /**
         * Creates a new BasicTag object.
         */
        public BasicTag() {
            super();
        }

        /**
         * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
         */
        public int doStartTag() throws JspException {
            pageContext.setAttribute("currentIter", new Integer(iterate));
            pageContext.setAttribute("atBegin", new Integer(0));

            return includeBody ? EVAL_BODY_INCLUDE : SKIP_BODY;
        }

        /**
         * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
         */
        public int doEndTag() throws JspException {
            pageContext.setAttribute("atEnd", new Integer(iterate));

            return includePage ? EVAL_PAGE : SKIP_PAGE;
        }

        /**
         * @see javax.servlet.jsp.tagext.TagSupport#doAfterBody()
         */
        public int doAfterBody() throws JspException {
            iterate -= 1;
            pageContext.setAttribute("currentIter", new Integer(iterate));

            if (iterate <= 0) {
                return SKIP_BODY;
            } else {
                return EVAL_BODY_AGAIN;
            }
        }

        /**
         * Getter for property includePage.
         *
         * @return Value of property includePage.
         *
         * @jsp.attribute required="true"
         *                rtexprvalue="true"
         *                description="The includePage attribute"
         */
        public boolean isIncludePage() {
            return includePage;
        }

        /**
         * Setter for property includePage.
         *
         * @param includePage New value of property includePage.
         */
        public void setIncludePage(boolean includePage) {
            this.includePage = includePage;
        }

        /**
         * Getter for property includeBody.
         *
         * @return Value of property includeBody.
         *
         * @jsp.attribute required="true"
         *                rtexprvalue="true"
         *                description="The includeBody attribute"
         */
        public boolean isIncludeBody() {
            return includeBody;
        }

        /**
         * Setter for property includeBody.
         *
         * @param includeBody New value of property includeBody.
         */
        public void setIncludeBody(boolean includeBody) {
            this.includeBody = includeBody;
        }

        /**
         * Getter for property iterate.
         *
         * @return Value of property iterate.
         *
         * @jsp.attribute required="true"
         *                rtexprvalue="true"
         *                description="The iterate attribute"
         */
        public int getIterate() {
            return iterate;
        }

        /**
         * Setter for property iterate.
         *
         * @param iterate New value of property iterate.
         */
        public void setIterate(int iterate) {
            this.iterate = iterate;
        }
    }
    Explanation of XDoclet Tags Used in the Custom Tag
    The example tag  illustrates the use of several helpful XDoclet tags. The tags and what they generate are displayed in the table below.

    XDoclet Tag Generated Code
    @jsp.tag name="BasicTag" Generated into the taglib's .tld file:

    <tag>
       <name>BasicTag</name>
       <tag-class>
           com.myeclipse.tutorial.customtag.BasicTag
       </tag-class>
       ...
    </tag>
    @jsp.variable
        name-given="currentIter"
        class="java.lang.Integer"
        scope="NESTED"
        declare="true"
    @jsp.variable
        name-given="atBegin"
        class="java.lang.Integer"
        scope="AT_BEGIN"
        declare="true"
    @jsp.variable
        name-given="atEnd"
        class="java.lang.Integer"
        scope="AT_END"
        declare="true"
    Generated into the taglib's .tld file:

    <tag>
       ...
       <variable>
          <name-given>currentIter</name-given>
          <variable-class>java.lang.Integer</variable-class>
      <declare>true</declare>
          <scope>NESTED</scope>
       </variable>
       <variable>
          <name-given>atBegin</name-given>
          <variable-class>java.lang.Integer</variable-class>
      <declare>true</declare>
          <scope>AT_BEGIN</scope>
       </variable>
       <variable>
          <name-given>atEnd</name-given>
          <variable-class>java.lang.Integer</variable-class>
      <declare>true</declare>
          <scope>AT_END</scope>
       </variable>
       ...
    </tag>
    @jsp.attribute required="true"
        rtexprvalue="true"
        description="The includePage attribute"
    @jsp.attribute required="true"
        rtexprvalue="true"
        description="The includeBody attribute"
    @jsp.attribute required="true"
        rtexprvalue="true"
        description="The iterate attribute"
    Generated into the taglib's .tld file:

    <tag>
       ...
       <attribute>
          <name>includePage</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[The includePage attribute]]></description>
       </attribute>
       <attribute>
          <name>includeBody</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[The includeBody attribute]]></description>
       </attribute>
       <attribute>
          <name>iterate</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[The iterate attribute]]></description>
       </attribute>
    </tag>

    4) Add a Folder Called 'merge' to the Project

    1. Select the project MyXDocletWeb in the Package Explorer
    2. Select File > New... > Folder,
    3. Populate it with the name merge, as shown in Figure 6, then press the Finish button.
      Creating the Merge Folder
      Figure 6. Creating the Merge Folder

    5) Create the taglibs.xml file

    1. Select the folder MyXDocletWeb/merge in the Package Explorer
    2. Select File > New... > XML,
    3. Populate it with the name taglibs.xml, as shown in Figure 7, then press the Finish button.
      Creating the taglibs.xml file
      Figure 7. Creating the taglibs.xml file
    Once taglibs.xml has been created and opened in the XML editor, completely replace the contents with the following:
    <taglib>
       <taglib-uri>/mytaglib</taglib-uri>
       <taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
    </taglib>

    6) Create the welcomefiles.xml file

    1. Select the folder MyXDocletWeb/merge in the Package Explorer
    2. Select File > New... > XML,
    3. Populate it with the name welcomefiles.xml then press the Finish button as you did for taglibs.xml.
    Once welcomefiles.xml has been created and opened in the XML editor, completely replace the contents with the following:
    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    7) Create the xdoclet-build.properties file

    1. Select the folder MyXDocletWeb in the Package Explorer
    2. Select File > New... > File,
    3. Populate it with the name xdoclet-build.properties, as shown in Figure 8, then press the Finish button.
      Creating the xdoclet-build.properties file
      Figure 8. Creating the xdoclet-build.properties file
      Once xdoclet-build.properties has been created and opened in the Text editor, completely replace the contents with the following:
    basic.servlet.hi = MyEclipse Rocks!
    basic.servlet.bye = Feel the power of XDoclet!

    8) Configure the Project for XDoclet Usage

    1. Right-click on the folder MyXDocletWeb in the Package Explorer
    2. Select Properties > XDoclet Configurations
    3. Right-click and select Add Standard as shown in Figure 9.
    4. Select Standard Web from the resulting dialog box. The resulting configuration is shown in Figure 10.
      Adding a Standard XDoclet Configuration
      Figure 9. Adding a Standard XDoclet Configuration
      Adding Standard Web Configuration
      Figure 10. Adding Standard Web Configuration
    5. Select deploymentdescriptor under the webdoclet entry and select and set the following values as shown in the table below and in Figure 11.
      Property Value
      Servletspec 2.3
      destDir WebRoot/WEB-INF
      displayName XDoclet Web Tutorial
      mergeDir merge
      Deployment Descriptor Settings
      Figure 11. Deployment Descriptor Settings
    6. Select jsptaglib under the webdoclet entry and select and set the following values as shown in the table below and in Figure 12.
      Property Value
      Jspversion 1.2
      destDir WebRoot/WEB-INF
      destinationFile mytaglib.tld
      shortname basic
      JSP Taglib Settings
      Figure 12. JSP Taglib Settings
    7. Select the OK button at the bottom of the Properties dialog to save the XDoclet Configurations. This will generate the file xdoclet-build.xml into the project folder.

    9) Setting XDoclet Ant Properties

    1. Right-click on the generated xdoclet-build.xml file in the Package Explorer and select Run Ant....
    2. On the dialg, titled MyXDocletWeb xdoclet-build.xml, select the Properties tab.
    3. Select the Add... button next to the Property files: list
    4. Browse to the project folder select xdoclet-build.properties.
    5. The resultant configuration will look like that in Figure 13.
      Adding Xdoclet Properties File
      Figure 13. Adding the Properties File
    6. Select the Refresh tab on the dialog and ensure that Refresh references after running tool is checked.
      Checking the Refresh Settings
      Figure 14. Checking the Refresh Settings
    7. Select the Apply button to save the changes.
    8. Select the Run button to process the XDoclet JavaDoc statements in the Java source with the Ant webdoclet task.
    9. After XDoclet runs, the files web.xml and mytaglib.tld will have been added to the WEB-INF directory as shown in Figure 15 below.
      Generated Files
      Figure 14. Generated Files

    10) Adding a JSP Page

    1. Select the project MyXDocletWeb in the Package Explorer
    2. Right-click and select New... > JSP,
    3. Populate the wizard page with the file name TestJSP.jsp, as shown in Figure 15, then press the Finish button.
      Creating a JSP
      Figure 15. Creating a JSP
    4. After the JSP is generated, it will be opened in the JSP editor. Replace the generated source code completely with the following contents and save the file.
    <%@&nbsp;page language="java" %>
    <%@&nbsp;taglib uri="/mytaglib" prefix="mytag" %>

    <html>
      <head>
        <title>I am a happy JSP page. Yeah!</title>
      </head>
      <body>
        <mytag:BasicTag includePage="true" includeBody="true" iterate="3">
          Current iteration is <%=currentIter%> <br/>
        </mytag:BasicTag>
      </body>
    </html>

    10) Adding an HTML Page

    1. Select the project MyXDocletWeb in the Package Explorer
    2. Right-click and select New... > HTML,
    3. Populate the wizard page with the file name index.html, as shown in Figure 16, then press the Finish button.
      Creating an HTML Page
      Figure 16. Creating an HTML Page
    4. After the HTML page is generated, it will be opened in the HTML editor. Replace the generated source code completely with the following contents and save the file.
    <html>
      <head>
        <title>XDoclet Web Tutorial</title>
      </head>
      <body>
        <br />
        <blockquote>
          <h3>XDoclet Web Tutorial</h3>
          <ul>
            <li><a href="TestJSP.jsp">Test Basic JSP Custom Tag</a></li>
            <li><a href="BasicServlet">Test Basic Servlet</a></li>
          </ul>
        </blockquote>
      </body>
    </html>

    11) Verify Project

    The project is now complete. To verify that the structure is complete, please compare your project to the one shown in Figure 17.
    Final Project Structure
    Figure 17. Final Project Structure

    12) Deploy the Project and Test

    1. Right-click on the MyXDocletWeb project and select MyEclipse > Add and Remove Project Deployments as shown in Figure 18.
      Opening the Deployment Dialog
      Figure 18. Opening the Deployment Dialog
    2. Select the Add button as shown in Figure 19.
      Adding a Deployment
      Figure 19. Adding a Deployment
    3. Select whatever server you've got configured as an exploded archive as shown in Figure 20.
      Picking the Application Server
      Figure 20. Picking a Server
    4. Select the OK button as shown in Figure 21.
      Completing Deployment
      Figure 21. Completing Deployment
    5. Start the server as shown in Figure 22.
      Starting the Application Server
      Figure 22. Starting the Server
    6. Open a browser and test the application. The results are shown in Figure 23.
      Testing the Application 1 Testing the Application 2 Testing the Application 3
      Figure 23. Testing the Application

      Conclusion

      This has been an introduction to XDoclet use for web applications within MyEclipse. Although the example application was a simple one, it was a complete application that included an HTML page, a JSP page, an XDoclet-based Servlet, and and XDoclet-based Tag library. Now that you know how the basics work, get out there and start simplifying your web development with MyEclipse and XDoclet!
  • Download Maven

    Cilck here to download from Official website
  • More script and css style : www.htmldrive.net