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
    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

    Maven-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 Maven

      At first glance Maven can appear to be many things, but in a nutshell Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:
      1.Builds
      2.Documentation
      3.Reporting
      4.Dependencies
      5.SCMs
      6.Releases
      7.Distribution
      If you want more background information on Maven you can check out The Philosophy of Maven and The History of Maven. Now let's move on to how you, the user, can benefit from using Maven.
      Maven is particularly useful because it can automatically manage massive dependency trees, especially transitive dependencies where Plugin X depends on Application Y, which depends on Shared Library Z. Using Maven, you should be able to quickly and easily retrieve all the dependencies that your plugin will need, and create a working development environment in just a few steps.
    • Limitations


      In order for Maven to find and download all of the necessary dependencies, you need to tell it where everything is stored. This is done via the settings file, settings.xml.
      Your plugin will depend on many different artifacts: the Atlassian application itself, Atlassian modules and various open-source libraries. All of those artifacts are stored in different Maven repositories scattered around the net. However, to simplify configuration and speed up downloads, Atlassian provides a Maven proxy that contains all of the dependencies for all of our applications. The example settings file contains just one repository entry for this proxy, and saves Maven from having to check several different repositories for each artifact it needs. You can read more about the repositories that are behind the Maven proxy.
      Atlassian will release binary and Javadoc artifacts for all of our product releases and their Atlassian-managed dependencies. We will release source artifacts wherever we can freely do so. Some of our closed-source artifacts will only be available via manual download for source license holders.
      We will also release various milestone and snapshot releases during application development, to aid plugin developers in testing their work against upcoming application releases.
      You will be able to find all of these artifacts in the Maven proxy.
    • Environment and requirement

      Maven is Java based tool, so the very first requirement is to have JDK installed in your machine.

      System Requirement

      JDK1.5 or above.
      Memoryno minimum requirement.
      Disk Spaceno minimum requirement.
      Operating Systemno minimum requirement.

      Step 1 - verify Java installation in your machine

      Now open console and execute the following java command.
      OSTaskCommand
      WindowsOpen Command Consolec:\> java -version
      LinuxOpen Command Terminal$ java -version
      MacOpen Terminalmachine:~ joseph$ java -version
      Let's verify the output for all the operating systems:
      OSOutput
      Windowsjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
      Linuxjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
      Macjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)
      If you do not have Java installed, install the Java Software Development Kit (SDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html. We are assuming Java 1.6.0_21 as installed version for this tutorial.

      Step 2: Set JAVA environment

      Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example
      OSOutput
      WindowsSet the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_21
      Linuxexport JAVA_HOME=/usr/local/java-current
      Macexport JAVA_HOME=/Library/Java/Home
      Append Java compiler location to System Path.
      OSOutput
      WindowsAppend the string ;C:\Program Files\Java\jdk1.6.0_21\bin to the end of the system variable, Path.
      Linuxexport PATH=$PATH:$JAVA_HOME/bin/
      Macnot required
      Verify Java Installation using java -version command explained above.

      Step 3: Download Maven archive

      Download Maven 2.2.1 from http://maven.apache.org/download.html
      OSArchive name
      Windowsapache-maven-2.0.11-bin.zip
      Linuxapache-maven-2.0.11-bin.tar.gz
      Macapache-maven-2.0.11-bin.tar.gz

      Step 4: Extract the Maven archive

      Extract the archive, to the directory you wish to install Maven 2.2.1. The subdirectory apache-maven-2.2.1 will be created from the archive.
      OSLocation (can be different based on your installation)
      WindowsC:\Program Files\Apache Software Foundation\apache-maven-2.2.1
      Linux/usr/local/apache-maven
      Mac/usr/local/apache-maven

      Step 5: Set Maven environment variables

      Add M2_HOME, M2, MAVEN_OPTS to environment variables.
      OSOutput
      WindowsSet the environment variables using system properties.
      M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1
      M2=%M2_HOME%\bin
      MAVEN_OPTS=-Xms256m -Xmx512m
      LinuxOpen command terminal and set environment variables.
      export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
      export M2=%M2_HOME%\bin
      export MAVEN_OPTS=-Xms256m -Xmx512m
      MacOpen command terminal and set environment variables.
      export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
      export M2=%M2_HOME%\bin
      export MAVEN_OPTS=-Xms256m -Xmx512m

      Step 6: Add Maven bin directory location to system path

      Now append M2 variable to System Path
      OSOutput
      WindowsAppend the string ;%M2% to the end of the system variable, Path.
      Linuxexport PATH=$M2:$PATH
      Macexport PATH=$M2:$PATH

      Step 8: Verify Maven installation

      Now open console, execute the following mvn command.
      OSTaskCommand
      WindowsOpen Command Consolec:\> mvn --version
      LinuxOpen Command Terminal$ mvn --version
      MacOpen Terminalmachine:~ joseph$ mvn --version
      Finally, verify the output of the above commands, which should be something as follows:
      OSOutput
      WindowsApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      LinuxApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      MacApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      Congratulations! you are now all set to use Apache Maven for your projects.

    • Installation steps for Maven

      Maven in 5 Minutes

      Prerequisites

      You must have an understanding of how to install software on your computer. If you do not know how to do this, please ask someone at your office, school, etc or pay someone to explain this to you. The Maven mailing lists are not the best place to ask for this advice.

      Installation

      Maven is a Java tool, so you must have Java installed in order to proceed.
      First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
      mvn --version
      
      It should print out your installed version of Maven, for example:
      Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
      Maven home: D:\apache-maven-3.0.3\bin\..
      Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
      Java home: E:\Program Files\Java\jdk1.6.0_25\jre
      Default locale: nl_NL, platform encoding: Cp1252
      OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
      
      Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.
      If you are using Windows, you should look at Windows Prerequisites to ensure that you are prepared to use Maven on Windows.

      Creating a Project

      You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:
      mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
      
      If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don't worry, there are ways to fix that.
      You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
      cd my-app
      
      Under this directory you will notice the following standard project structure.
      my-app
      |-- pom.xml
      `-- src
          |-- main
          |   `-- java
          |       `-- com
          |           `-- mycompany
          |               `-- app
          |                   `-- App.java
          `-- test
              `-- java
                  `-- com
                      `-- mycompany
                          `-- app
                              `-- AppTest.java
      
      The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project's Project Object Model, or POM.

      The POM

      The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
      
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
      
        <name>Maven Quick Start Archetype</name>
        <url>http://maven.apache.org</url>
      
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
          </dependency>
        </dependencies>
      </project>
      

      What did I just do?

      You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items".

      Build the Project

      mvn package
      
      The command line will print out various actions, and end with the following:
       ...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESSFUL
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 2 seconds
      [INFO] Finished at: Thu Jul 07 21:34:52 CEST 2011
      [INFO] Final Memory: 3M/6M
      [INFO] ------------------------------------------------------------------------
      
      Unlike the first command executed (archetype:generate) you may notice the second is simply a single word - package. Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, if we execute the compile phase, the phases that actually get executed are:
      1. validate
      2. generate-sources
      3. process-sources
      4. generate-resources
      5. process-resources
      6. compile
      You may test the newly compiled and packaged JAR with the following command:
      java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
      
      Which will print the quintessential:
      Hello World!
      
    • Install maven in eclispe IDE

      Eclipse provides an excellent plugin m2eclipse which seamlessly integrates Maven and Eclipse together.
      Some of features of m2eclipse are listed below
      • You can run Maven goals from Eclipse.
      • You can view the output of Maven commands inside the Eclipse using its own console.
      • You can update maven dependencies with IDE.
      • You can Launch Maven builds from within Eclipse.
      • It does the dependency management for Eclipse build path based on Maven's pom.xml.
      • It resolves Maven dependencies from the Eclipse workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • It automatic downloads required dependencies and sources from the remote Maven repositories.
      • It provides wizards for creating new Maven projects, pom.xml and to enable Maven support on existing projects
      • It provides quick search for dependencies in remote Maven repositories

      Installing m2eclipse plugin

      Use one of the following links to install m2eclipse:
      EclipseURL
      Eclipse 3.5 (Gallileo)Installing m2eclipse in Eclipse 3.5 (Gallileo)
      Eclipse 3.6 (Helios)Installing m2eclipse in Eclipse 3.6 (Helios)
      Following example will help you to leverage benefits of integrating Eclipse and maven.

      Import a maven project in Eclipse

      • Open Eclipse.
      • Select File > Import > option.
      • Select Maven Projects Option. Click on Next Button.
      Import a maven project in Eclipse.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      • Click Finish Button.
      Import a maven project in Eclipse.
      Now, you can see the maven project in eclipse.
      maven project in Eclipse.
      Now, have a look at consumerBanking project properties.You can see that Eclipse has added Maven dependencies to java build path.
      Java Build Path having Maven dependencies.
      Now, Its time to build this project using maven capability of eclipse.

      • Right Click on consumerBanking project to open context menu.
      • Select Run as option
      • Then maven package option
      Maven will start building the project. You can see the output in Eclipse Console
      [INFO] Scanning for projects...
      [INFO] -------------------------------------------------------------------
      [INFO] Building consumerBanking
      [INFO] 
      [INFO] Id: com.companyname.bank:consumerBanking:jar:1.0-SNAPSHOT
      [INFO] task-segment: [package]
      [INFO] -------------------------------------------------------------------
      [INFO] [resources:resources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:compile]
      [INFO] Nothing to compile - all classes are up to date
      [INFO] [resources:testResources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:testCompile]
      [INFO] Nothing to compile - all classes are up to date
      [INFO] [surefire:test]
      [INFO] Surefire report directory: 
      C:\MVN\consumerBanking\target\surefire-reports
      
      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running com.companyname.bank.AppTest
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
      
      Results :
      
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
      
      [INFO] [jar:jar]
      [INFO] -------------------------------------------------------------------
      [INFO] BUILD SUCCESSFUL
      [INFO] -------------------------------------------------------------------
      [INFO] Total time: 1 second
      [INFO] Finished at: Thu Jul 12 18:18:24 IST 2012
      [INFO] Final Memory: 2M/15M
      [INFO] -------------------------------------------------------------------
      
      Run maven command using run as option. Now, right click on App.java. Select Run As option. Select As Java Application.

      You will see the result
      Hello World!
      



    • Install maven plugin in Netbeans

      NetBeans 6.7 and newer has inbuild support for Maven. In case of previous version, Maven plugin is available in plugin Manager. We're using NetBeans 6.9 in this example.
      Some of features of NetBeans are listed below
      • You can run Maven goals from NetBeans.
      • You can can view the output of Maven commands inside the NetBeans using its own console.
      • You can update maven dependencies with IDE.
      • You can Launch Maven builds from within NetBeans.
      • NetBeans does the dependency management automatically based on Maven's pom.xml.
      • NetBeans resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • NetBeans automatic downloads required dependencies and sources from the remote Maven repositories.
      • NetBeans provides wizards for creating new Maven projects, pom.xml
      • NetBeans provides a Maven Repository browser that enables you to view your local repository and registered external Maven repositories.
      Following example will help you to leverage benefits of integrating NetBeans and Maven.

      Open a maven project in NetBeans

      • Open NetBeans.
      • Select File Menu > Open Project option.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      Open a Maven project in NetBeans.
      Now, you can see the maven project in NetBeans.Have a look at consumerBanking project Libraries and Test Libraries.You can see that NetBeans has added Maven dependencies to its build path.
      Maven project in NetBeans.

      Build a maven project in NetBeans

      Now, Its time to build this project using maven capability of NetBeans.

      • Right Click on consumerBanking project to open context menu.
      • Select Clean and Build as option
      Build a Maven project in NetBeans. Maven will start building the project. You can see the output in NetBeans Console
      NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install'
      NetBeans:      JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
      Scanning for projects...
      ------------------------------------------------------------------------
      Building consumerBanking
         task-segment: [clean, install]
      ------------------------------------------------------------------------
      [clean:clean]
      [resources:resources]
      [WARNING] Using platform encoding (Cp1252 actually)
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
      [compiler:compile]
      Compiling 2 source files to C:\MVN\consumerBanking\target\classes
      [resources:testResources]
      [WARNING] Using platform encoding (Cp1252 actually)
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources
      [compiler:testCompile]
      Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes
      [surefire:test]
      Surefire report directory: C:\MVN\consumerBanking\target\surefire-reports
      
      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running com.companyname.bank.AppTest
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec
      
      Results :
      
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
      
      [jar:jar]
      Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
      [install:install]
      Installing C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
      to C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\
      1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar
      ------------------------------------------------------------------------
      BUILD SUCCESSFUL
      ------------------------------------------------------------------------
      Total time: 9 seconds
      Finished at: Thu Jul 19 12:57:28 IST 2012
      Final Memory: 16M/85M
      ------------------------------------------------------------------------
      

      Run Application in NetBeans

      Now, right click on App.java. Select Run File As option. You will see the result in NetBeans Console.
      NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime 
      -Dexec.args=-classpath %classpath com.companyname.bank.App 
      -Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe 
      -Dnetbeans.execution=true process-classes 
      org.codehaus.mojo:exec-maven-plugin:1.1.1:exec'
      NetBeans:      JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
      Scanning for projects...
      ------------------------------------------------------------------------
      Building consumerBanking
         task-segment: [process-classes, 
         org.codehaus.mojo:exec-maven-plugin:1.1.1:exec]
      ------------------------------------------------------------------------
      [resources:resources]
      [WARNING] Using platform encoding (Cp1252 actually) 
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
      [compiler:compile]
      Nothing to compile - all classes are up to date
      [exec:exec]
      Hello World!
      ------------------------------------------------------------------------
      BUILD SUCCESSFUL
      ------------------------------------------------------------------------
      Total time: 1 second
      Finished at: Thu Jul 19 14:18:13 IST 2012
      Final Memory: 7M/64M
      ------------------------------------------------------------------------
      

    • Install maven plugin in IntelliJ IDEA

      IntelliJ IDEA has inbuild support for Maven. We're using IntelliJ IDEA Community Edition 11.1 in this example.
      Some of features of IntelliJ IDEA are listed below
      • You can run Maven goals from IntelliJ IDEA.
      • You can can view the output of Maven commands inside the IntelliJ IDEA using its own console.
      • You can update maven dependencies within IDE.
      • You can Launch Maven builds from within IntelliJ IDEA.
      • IntelliJ IDEA does the dependency management automatically based on Maven's pom.xml.
      • IntelliJ IDEA resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • IntelliJ IDEA automatic downloads required dependencies and sources from the remote Maven repositories.
      • IntelliJ IDEA provides wizards for creating new Maven projects, pom.xml
      Following example will help you to leverage benefits of integrating IntelliJ IDEA and Maven.

      Create a new project in IntelliJ IDEA

      We'll import Maven project using New Project Wizard.
      • Open IntelliJ IDEA.
      • Select File Menu > New Project Option.
      • Select import project from existing model.
      New Project in IntelliJ IDEA, step 1.
      • Select Maven option
      New Project in IntelliJ IDEA, step 2.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      New Project in IntelliJ IDEA, step 3.
      • Select Maven project to import.
      New Project in IntelliJ IDEA, step 4.
      • Enter name of the project and click finish.
      New Project in IntelliJ IDEA, step 5.
      Now, you can see the maven project in IntelliJ IDEA.Have a look at consumerBanking project external libraries.You can see that IntelliJ IDEA has added Maven dependencies to its build path under Maven section.
      Maven project in IntelliJ IDEA.

      Build a maven project in IntelliJ IDEA

      Now, Its time to build this project using capability of IntelliJ IDEA.

      • Select consumerBanking project.
      • Select Buid menu > Rebuild Project Option
      You can see the output in IntelliJ IDEA Console
      4:01:56 PM Compilation completed successfully
      

      Run Application in IntelliJ IDEA

      • Select consumerBanking project.
      • Right click on App.java to open context menu.
      • select Run App.main()
      Maven project in IntelliJ IDEA. You will see the result in IntelliJ IDEA Console.
      "C:\Program Files\Java\jdk1.6.0_21\bin\java"
      -Didea.launcher.port=7533 
      "-Didea.launcher.bin.path=
      C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin"
      -Dfile.encoding=UTF-8 
      -classpath "C:\Program Files\Java\jdk1.6.0_21\jre\lib\charsets.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar
      C:\MVN\consumerBanking\target\classes;
      C:\Program Files\JetBrains\
      IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar" 
      com.intellij.rt.execution.application.AppMain com.companyname.bank.App
      Hello World!
      
      Process finished with exit code 0


    • Download Maven

      Cilck here to download from Official website
    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 Maven

      At first glance Maven can appear to be many things, but in a nutshell Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:
      1.Builds
      2.Documentation
      3.Reporting
      4.Dependencies
      5.SCMs
      6.Releases
      7.Distribution
      If you want more background information on Maven you can check out The Philosophy of Maven and The History of Maven. Now let's move on to how you, the user, can benefit from using Maven.
      Maven is particularly useful because it can automatically manage massive dependency trees, especially transitive dependencies where Plugin X depends on Application Y, which depends on Shared Library Z. Using Maven, you should be able to quickly and easily retrieve all the dependencies that your plugin will need, and create a working development environment in just a few steps.
    • Limitations


      In order for Maven to find and download all of the necessary dependencies, you need to tell it where everything is stored. This is done via the settings file, settings.xml.
      Your plugin will depend on many different artifacts: the Atlassian application itself, Atlassian modules and various open-source libraries. All of those artifacts are stored in different Maven repositories scattered around the net. However, to simplify configuration and speed up downloads, Atlassian provides a Maven proxy that contains all of the dependencies for all of our applications. The example settings file contains just one repository entry for this proxy, and saves Maven from having to check several different repositories for each artifact it needs. You can read more about the repositories that are behind the Maven proxy.
      Atlassian will release binary and Javadoc artifacts for all of our product releases and their Atlassian-managed dependencies. We will release source artifacts wherever we can freely do so. Some of our closed-source artifacts will only be available via manual download for source license holders.
      We will also release various milestone and snapshot releases during application development, to aid plugin developers in testing their work against upcoming application releases.
      You will be able to find all of these artifacts in the Maven proxy.
    • Environment and requirement

      Maven is Java based tool, so the very first requirement is to have JDK installed in your machine.

      System Requirement

      JDK1.5 or above.
      Memoryno minimum requirement.
      Disk Spaceno minimum requirement.
      Operating Systemno minimum requirement.

      Step 1 - verify Java installation in your machine

      Now open console and execute the following java command.
      OSTaskCommand
      WindowsOpen Command Consolec:\> java -version
      LinuxOpen Command Terminal$ java -version
      MacOpen Terminalmachine:~ joseph$ java -version
      Let's verify the output for all the operating systems:
      OSOutput
      Windowsjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
      Linuxjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
      Macjava version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)
      If you do not have Java installed, install the Java Software Development Kit (SDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html. We are assuming Java 1.6.0_21 as installed version for this tutorial.

      Step 2: Set JAVA environment

      Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example
      OSOutput
      WindowsSet the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_21
      Linuxexport JAVA_HOME=/usr/local/java-current
      Macexport JAVA_HOME=/Library/Java/Home
      Append Java compiler location to System Path.
      OSOutput
      WindowsAppend the string ;C:\Program Files\Java\jdk1.6.0_21\bin to the end of the system variable, Path.
      Linuxexport PATH=$PATH:$JAVA_HOME/bin/
      Macnot required
      Verify Java Installation using java -version command explained above.

      Step 3: Download Maven archive

      Download Maven 2.2.1 from http://maven.apache.org/download.html
      OSArchive name
      Windowsapache-maven-2.0.11-bin.zip
      Linuxapache-maven-2.0.11-bin.tar.gz
      Macapache-maven-2.0.11-bin.tar.gz

      Step 4: Extract the Maven archive

      Extract the archive, to the directory you wish to install Maven 2.2.1. The subdirectory apache-maven-2.2.1 will be created from the archive.
      OSLocation (can be different based on your installation)
      WindowsC:\Program Files\Apache Software Foundation\apache-maven-2.2.1
      Linux/usr/local/apache-maven
      Mac/usr/local/apache-maven

      Step 5: Set Maven environment variables

      Add M2_HOME, M2, MAVEN_OPTS to environment variables.
      OSOutput
      WindowsSet the environment variables using system properties.
      M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1
      M2=%M2_HOME%\bin
      MAVEN_OPTS=-Xms256m -Xmx512m
      LinuxOpen command terminal and set environment variables.
      export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
      export M2=%M2_HOME%\bin
      export MAVEN_OPTS=-Xms256m -Xmx512m
      MacOpen command terminal and set environment variables.
      export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
      export M2=%M2_HOME%\bin
      export MAVEN_OPTS=-Xms256m -Xmx512m

      Step 6: Add Maven bin directory location to system path

      Now append M2 variable to System Path
      OSOutput
      WindowsAppend the string ;%M2% to the end of the system variable, Path.
      Linuxexport PATH=$M2:$PATH
      Macexport PATH=$M2:$PATH

      Step 8: Verify Maven installation

      Now open console, execute the following mvn command.
      OSTaskCommand
      WindowsOpen Command Consolec:\> mvn --version
      LinuxOpen Command Terminal$ mvn --version
      MacOpen Terminalmachine:~ joseph$ mvn --version
      Finally, verify the output of the above commands, which should be something as follows:
      OSOutput
      WindowsApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      LinuxApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      MacApache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
      Java version: 1.6.0_21
      Java home: C:\Program Files\Java\jdk1.6.0_21\jre
      Congratulations! you are now all set to use Apache Maven for your projects.

    • Installation steps for Maven

      Maven in 5 Minutes

      Prerequisites

      You must have an understanding of how to install software on your computer. If you do not know how to do this, please ask someone at your office, school, etc or pay someone to explain this to you. The Maven mailing lists are not the best place to ask for this advice.

      Installation

      Maven is a Java tool, so you must have Java installed in order to proceed.
      First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
      mvn --version
      
      It should print out your installed version of Maven, for example:
      Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
      Maven home: D:\apache-maven-3.0.3\bin\..
      Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
      Java home: E:\Program Files\Java\jdk1.6.0_25\jre
      Default locale: nl_NL, platform encoding: Cp1252
      OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
      
      Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.
      If you are using Windows, you should look at Windows Prerequisites to ensure that you are prepared to use Maven on Windows.

      Creating a Project

      You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:
      mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
      
      If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don't worry, there are ways to fix that.
      You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
      cd my-app
      
      Under this directory you will notice the following standard project structure.
      my-app
      |-- pom.xml
      `-- src
          |-- main
          |   `-- java
          |       `-- com
          |           `-- mycompany
          |               `-- app
          |                   `-- App.java
          `-- test
              `-- java
                  `-- com
                      `-- mycompany
                          `-- app
                              `-- AppTest.java
      
      The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project's Project Object Model, or POM.

      The POM

      The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
      
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
      
        <name>Maven Quick Start Archetype</name>
        <url>http://maven.apache.org</url>
      
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
          </dependency>
        </dependencies>
      </project>
      

      What did I just do?

      You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items".

      Build the Project

      mvn package
      
      The command line will print out various actions, and end with the following:
       ...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESSFUL
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 2 seconds
      [INFO] Finished at: Thu Jul 07 21:34:52 CEST 2011
      [INFO] Final Memory: 3M/6M
      [INFO] ------------------------------------------------------------------------
      
      Unlike the first command executed (archetype:generate) you may notice the second is simply a single word - package. Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, if we execute the compile phase, the phases that actually get executed are:
      1. validate
      2. generate-sources
      3. process-sources
      4. generate-resources
      5. process-resources
      6. compile
      You may test the newly compiled and packaged JAR with the following command:
      java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
      
      Which will print the quintessential:
      Hello World!
      
    • Install maven in eclispe IDE

      Eclipse provides an excellent plugin m2eclipse which seamlessly integrates Maven and Eclipse together.
      Some of features of m2eclipse are listed below
      • You can run Maven goals from Eclipse.
      • You can view the output of Maven commands inside the Eclipse using its own console.
      • You can update maven dependencies with IDE.
      • You can Launch Maven builds from within Eclipse.
      • It does the dependency management for Eclipse build path based on Maven's pom.xml.
      • It resolves Maven dependencies from the Eclipse workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • It automatic downloads required dependencies and sources from the remote Maven repositories.
      • It provides wizards for creating new Maven projects, pom.xml and to enable Maven support on existing projects
      • It provides quick search for dependencies in remote Maven repositories

      Installing m2eclipse plugin

      Use one of the following links to install m2eclipse:
      EclipseURL
      Eclipse 3.5 (Gallileo)Installing m2eclipse in Eclipse 3.5 (Gallileo)
      Eclipse 3.6 (Helios)Installing m2eclipse in Eclipse 3.6 (Helios)
      Following example will help you to leverage benefits of integrating Eclipse and maven.

      Import a maven project in Eclipse

      • Open Eclipse.
      • Select File > Import > option.
      • Select Maven Projects Option. Click on Next Button.
      Import a maven project in Eclipse.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      • Click Finish Button.
      Import a maven project in Eclipse.
      Now, you can see the maven project in eclipse.
      maven project in Eclipse.
      Now, have a look at consumerBanking project properties.You can see that Eclipse has added Maven dependencies to java build path.
      Java Build Path having Maven dependencies.
      Now, Its time to build this project using maven capability of eclipse.

      • Right Click on consumerBanking project to open context menu.
      • Select Run as option
      • Then maven package option
      Maven will start building the project. You can see the output in Eclipse Console
      [INFO] Scanning for projects...
      [INFO] -------------------------------------------------------------------
      [INFO] Building consumerBanking
      [INFO] 
      [INFO] Id: com.companyname.bank:consumerBanking:jar:1.0-SNAPSHOT
      [INFO] task-segment: [package]
      [INFO] -------------------------------------------------------------------
      [INFO] [resources:resources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:compile]
      [INFO] Nothing to compile - all classes are up to date
      [INFO] [resources:testResources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:testCompile]
      [INFO] Nothing to compile - all classes are up to date
      [INFO] [surefire:test]
      [INFO] Surefire report directory: 
      C:\MVN\consumerBanking\target\surefire-reports
      
      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running com.companyname.bank.AppTest
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
      
      Results :
      
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
      
      [INFO] [jar:jar]
      [INFO] -------------------------------------------------------------------
      [INFO] BUILD SUCCESSFUL
      [INFO] -------------------------------------------------------------------
      [INFO] Total time: 1 second
      [INFO] Finished at: Thu Jul 12 18:18:24 IST 2012
      [INFO] Final Memory: 2M/15M
      [INFO] -------------------------------------------------------------------
      
      Run maven command using run as option. Now, right click on App.java. Select Run As option. Select As Java Application.

      You will see the result
      Hello World!
      



    • Install maven plugin in Netbeans

      NetBeans 6.7 and newer has inbuild support for Maven. In case of previous version, Maven plugin is available in plugin Manager. We're using NetBeans 6.9 in this example.
      Some of features of NetBeans are listed below
      • You can run Maven goals from NetBeans.
      • You can can view the output of Maven commands inside the NetBeans using its own console.
      • You can update maven dependencies with IDE.
      • You can Launch Maven builds from within NetBeans.
      • NetBeans does the dependency management automatically based on Maven's pom.xml.
      • NetBeans resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • NetBeans automatic downloads required dependencies and sources from the remote Maven repositories.
      • NetBeans provides wizards for creating new Maven projects, pom.xml
      • NetBeans provides a Maven Repository browser that enables you to view your local repository and registered external Maven repositories.
      Following example will help you to leverage benefits of integrating NetBeans and Maven.

      Open a maven project in NetBeans

      • Open NetBeans.
      • Select File Menu > Open Project option.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      Open a Maven project in NetBeans.
      Now, you can see the maven project in NetBeans.Have a look at consumerBanking project Libraries and Test Libraries.You can see that NetBeans has added Maven dependencies to its build path.
      Maven project in NetBeans.

      Build a maven project in NetBeans

      Now, Its time to build this project using maven capability of NetBeans.

      • Right Click on consumerBanking project to open context menu.
      • Select Clean and Build as option
      Build a Maven project in NetBeans. Maven will start building the project. You can see the output in NetBeans Console
      NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install'
      NetBeans:      JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
      Scanning for projects...
      ------------------------------------------------------------------------
      Building consumerBanking
         task-segment: [clean, install]
      ------------------------------------------------------------------------
      [clean:clean]
      [resources:resources]
      [WARNING] Using platform encoding (Cp1252 actually)
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
      [compiler:compile]
      Compiling 2 source files to C:\MVN\consumerBanking\target\classes
      [resources:testResources]
      [WARNING] Using platform encoding (Cp1252 actually)
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources
      [compiler:testCompile]
      Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes
      [surefire:test]
      Surefire report directory: C:\MVN\consumerBanking\target\surefire-reports
      
      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running com.companyname.bank.AppTest
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec
      
      Results :
      
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
      
      [jar:jar]
      Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
      [install:install]
      Installing C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
      to C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\
      1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar
      ------------------------------------------------------------------------
      BUILD SUCCESSFUL
      ------------------------------------------------------------------------
      Total time: 9 seconds
      Finished at: Thu Jul 19 12:57:28 IST 2012
      Final Memory: 16M/85M
      ------------------------------------------------------------------------
      

      Run Application in NetBeans

      Now, right click on App.java. Select Run File As option. You will see the result in NetBeans Console.
      NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime 
      -Dexec.args=-classpath %classpath com.companyname.bank.App 
      -Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe 
      -Dnetbeans.execution=true process-classes 
      org.codehaus.mojo:exec-maven-plugin:1.1.1:exec'
      NetBeans:      JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
      Scanning for projects...
      ------------------------------------------------------------------------
      Building consumerBanking
         task-segment: [process-classes, 
         org.codehaus.mojo:exec-maven-plugin:1.1.1:exec]
      ------------------------------------------------------------------------
      [resources:resources]
      [WARNING] Using platform encoding (Cp1252 actually) 
      to copy filtered resources, i.e. build is platform dependent!
      skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
      [compiler:compile]
      Nothing to compile - all classes are up to date
      [exec:exec]
      Hello World!
      ------------------------------------------------------------------------
      BUILD SUCCESSFUL
      ------------------------------------------------------------------------
      Total time: 1 second
      Finished at: Thu Jul 19 14:18:13 IST 2012
      Final Memory: 7M/64M
      ------------------------------------------------------------------------
      

    • Install maven plugin in IntelliJ IDEA

      IntelliJ IDEA has inbuild support for Maven. We're using IntelliJ IDEA Community Edition 11.1 in this example.
      Some of features of IntelliJ IDEA are listed below
      • You can run Maven goals from IntelliJ IDEA.
      • You can can view the output of Maven commands inside the IntelliJ IDEA using its own console.
      • You can update maven dependencies within IDE.
      • You can Launch Maven builds from within IntelliJ IDEA.
      • IntelliJ IDEA does the dependency management automatically based on Maven's pom.xml.
      • IntelliJ IDEA resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
      • IntelliJ IDEA automatic downloads required dependencies and sources from the remote Maven repositories.
      • IntelliJ IDEA provides wizards for creating new Maven projects, pom.xml
      Following example will help you to leverage benefits of integrating IntelliJ IDEA and Maven.

      Create a new project in IntelliJ IDEA

      We'll import Maven project using New Project Wizard.
      • Open IntelliJ IDEA.
      • Select File Menu > New Project Option.
      • Select import project from existing model.
      New Project in IntelliJ IDEA, step 1.
      • Select Maven option
      New Project in IntelliJ IDEA, step 2.
      • Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
      New Project in IntelliJ IDEA, step 3.
      • Select Maven project to import.
      New Project in IntelliJ IDEA, step 4.
      • Enter name of the project and click finish.
      New Project in IntelliJ IDEA, step 5.
      Now, you can see the maven project in IntelliJ IDEA.Have a look at consumerBanking project external libraries.You can see that IntelliJ IDEA has added Maven dependencies to its build path under Maven section.
      Maven project in IntelliJ IDEA.

      Build a maven project in IntelliJ IDEA

      Now, Its time to build this project using capability of IntelliJ IDEA.

      • Select consumerBanking project.
      • Select Buid menu > Rebuild Project Option
      You can see the output in IntelliJ IDEA Console
      4:01:56 PM Compilation completed successfully
      

      Run Application in IntelliJ IDEA

      • Select consumerBanking project.
      • Right click on App.java to open context menu.
      • select Run App.main()
      Maven project in IntelliJ IDEA. You will see the result in IntelliJ IDEA Console.
      "C:\Program Files\Java\jdk1.6.0_21\bin\java"
      -Didea.launcher.port=7533 
      "-Didea.launcher.bin.path=
      C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin"
      -Dfile.encoding=UTF-8 
      -classpath "C:\Program Files\Java\jdk1.6.0_21\jre\lib\charsets.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar;
      C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar
      C:\MVN\consumerBanking\target\classes;
      C:\Program Files\JetBrains\
      IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar" 
      com.intellij.rt.execution.application.AppMain com.companyname.bank.App
      Hello World!
      
      Process finished with exit code 0


    • Download Maven

      Cilck here to download from Official website