SlideShare a Scribd company logo
1



  The author has made every effort in the preparation of this book to ensure the accuracy of the information.
 However, information in this book is sold without warranty either expressed or implied. The author will not be
     held liable for any damages caused or alleged to be caused either directly or indirectly by this book.




         Java, Eclipse, Maven & JSF tutorial

  Maven 2 is a powerful tool that promotes convention over configuration and you need to
    integrate it into one of the popular integrated development environments (IDEs) called
 eclipse to make your work easier, thus increasing your productivity and project quality. This
tutorial provides an example of how to make Maven and Eclipse collaborate. Also covers the
                                   popular JSF Web framework.




                                                     by




                                         K. Arulkumaran


                                            & A. Sivayini




                Website: http://www.lulu.com/java-success


              Feedback email: java-interview@hotmail.com
2

                                                 Table Of Contents


Notations ..................................................................................................................... 3
Tutorial 1 – Java, Maven and Eclipse .................................................................. 4
Tutorial 2 – Java Web, Maven and Eclipse....................................................... 16
Tutorial 3 – JSF, Maven and Eclipse.................................................................. 28
Appendix ................................................................................................................... 58
3
                                     Notations

Command prompt:




Eclipse:




File Explorer or Windows Explorer:




Internet Explorer:
4
Tutorial 1 – Java, Maven and Eclipse


This tutorial will guide you through building a simple Java application from
scratch using popular tools like eclipse and maven. This tutorial will be handy
for those who are new to maven/eclipse/Java.
Install the following programs. In this tutorial I have installed them under c:/java.

        Java 1.5 (JDK1.5 & JRE1.5)
        site: http://java.sun.com/javase/downloads/index_jdk5.jsp. . Also set the environment
        properties JAVA_HOME (e.g. C:javajdk1.5.0) and add to the path (e.g.
        %JAVA_HOME%bin). If installed correctly you should be able to test it by opening a
        command prompt and typing

        C:>java –version

        Results in:

        java version "1.5.0_11"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
        Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

        Maven 2.0.7. Site: http://maven.apache.org/download.html. Set the environment
        variables M2_HOME (e.g. C:javamaven-2.0.7) and add to the path (e.g.
        %M2_HOME%bin). If installed correctly you should be able to test it by opening a
        command prompt and typing:

        C:>mvn --version

        Results in:

        Maven version: 2.0.7
        Java version: 1.5.0_11
        OS name: "windows xp" version: "5.1" arch: "x86"

        Open the “settings.xml” file under C:javamaven-2.0.7conf folder and set your
        local repository as follows:

        <localRepository>C:/java/.m2/repository</localRepository>

        Also if your internet access is through a proxy server then configure your proxy server
        in “settings.xml” for example:

        <proxy>
            <id>optional</id>
            <active>true</active>
            <protocol>http</protocol>
            <username>proxyuser</username>
            <password>proxypass</password>
            <host>webproxy</host>
            <port>8080</port>
            <nonProxyHosts>local.net,some.host.com</nonProxyHosts>
        </proxy>


        Eclipse 3.3.0 (Europa). Site: http://www.eclipse.org/downloads/

So far we have installed the programs under c:/java. Now we need to create a folder for
our tutorials as c:/tutorials. Also create an eclipse workspace “C:javaeclipse-tutorial-
5
workspace” where metadata get stored. It is the best practice to separate IDE specific (i.e.
C:javaeclipse-tutorial-workspace) files from the projects (i.e. c:/tutorials) specific files.

C:/java folder




C:/tutorials folder
6
    Now let’s have maven into play. One of the powers of maven is its principle of “convention
    over configuration”. You can run the following command to create a maven project structure.

    C:tutorials>mvn archetype:create -DgroupId=com.mytutorial -DartifactId=simple

    The above command results in some directories & files created under c:/tutorials. E.g.

    C:tutorialssimple     project called “simple”
    C:tutorialssimplesrc    “src” folder under which you have “main” & “test” etc.
    C:tutorialssimplepom.xml       the basic maven Project Object Model file.

Important (optional step): The plug-ins attached to lifecycle phases should be downloaded
and stored automatically (i.e. without having to declare them in pom.xml) exactly at the moment
they are needed. For example, if you call mvn compile from the command line. The plugins that
you call from the command line are downloaded and stored in the local repository only when you
call them (i.e. exactly when you type the command in the command line) even if they are
configured in your pom.xml. You can also explicitly define the plug-ins and their version numbers
in your pom.xml file as shown below in bold directly under the root element (i.e. <project>).

    <project ………….>
    ………………….
    <build>
        <pluginManagement>
             <plugins>
                     <plugin>
                             <groupId>org.apache.maven.plugins</groupId>
                             <artifactId>maven-compiler-plugin</artifactId>
                             <version>2.0.2</version>
                             <configuration>
                                      <source>1.5</source>
                                      <target>1.5</target>
                             </configuration>
                     </plugin>

                     <plugin>
                             <groupId>org.apache.maven.plugins</groupId>
                             <artifactId>maven-eclipse-plugin</artifactId>
                             <version>2.4</version>
                             <configuration>
                                  <downloadSources>false</downloadSources>
                                  <wtpversion>1.5</wtpversion>
                             </configuration>
                     </plugin>
             </plugins>
         </pluginManagement>
    </build>
    ………………….
    </project>

    Note: Maven is a plug-in execution framework. You can look for available plug-ins at
    http://maven.apache.org/plugins/. You can add this plug-ins as required. So if you have any
    issue(s) in automatically downloading (e.g. due to metadata files getting corrupted) or you
    want to override any plug-in configuration then use the above mentioned optional-step. Refer
    appendix for sample pom.xml with other plugins added.

    Note: You need to have an internet connection so that maven can download the plug-ins from
    its central repository at http://repo1.maven.org/ (especially http://repo1.maven.org/maven2/ ).
    The above mentioned plug-ins are based on their groupId under
    http://repo1.maven.org/maven2/org/apache/maven/plugins/.


    Note: You can find the documentation on plug-ins at mave2 home site
    http://maven.apache.org/plugins/index.html.
7




The pom.xml file with plug-in details (plug-in-details are optional)




         Open up eclipse with workspace: C:javaeclipse-tutorial-workspace. Close the welcome
         screen and you should get an empty workbench.
8




Eclipse needs to know the path to the local maven repository. Therefore the classpath variable
M2_REPO has to be set. Exit out of eclipse and execute the following command in a
command prompt. The following command will be making use of the maven-eclipse-plugin.

C:tutorials>mvn -Declipse.workspace=C:javaeclipse-tutorial-workspace eclipse:add-
maven-repo

Results in:

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [eclipse:add-maven-repo] (aggregator-style)
[INFO] ----------------------------------------------------------------------------
[INFO] [eclipse:add-maven-repo]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Aug 01 13:38:15 EST 2007
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------

After executing this command, you open up your eclipse and check if this variable
M2_REPO has been added. Important: If you had eclipse open while executing the above
mvn command you would not see this class path variable M2_REPO (e.g.
C:/java/.m2/repository). In eclipse under Window Preferences
9




Note: Alternatively you can manually add this directly into eclipse without having to
run the mvn command shown above.

If you have a simple java project which is made up of only one module, using eclipse is very
simple. Now let us put the eclipse plug-in to the test of generating eclipse metadata (i.e.
.project, .classpath files). To generate the eclipse metadata files from your pom.xml you
execute the following command:

C:tutorials> cd simple
C:tutorialssimple>mvn eclipse:eclipse


After running this command if you check your local maven repository folder
C:java.m2repository should have some dependency jars downloaded from the maven
repository site http://repo1.maven.org/maven2 and installed into your local repository
C:java.m2repository. Also under your project C:tutorialssimple, you should have some
eclipse related files created like .project and .classpath.


Note: You can find your downloaded plug-ins in your local repository
“C:/java/.m2/repository” which you set earlier in your settings.xml file under
%M2_HOME%conf (i.e. C:javamaven-2.0.7conf)


Now you get back to your eclipse and import this “simple” project as shown below. File
Import.
10




Click “Next”.




Click “Finish”. Now you should have the project in eclipse.
11




The “mvn eclipse:eclipse” command also has automatically added build dependencies into
your eclipse as shown below by using the M2_REPO class variable, which we set earlier
using “mvn -Declipse.workspace=C:javaeclipse-tutorial-workspace eclipse:add-maven-
repo” command. Isn’t that cool. You can add any additional dependencies into your
“pom.xml” file and then run “mvn eclipse:clean eclipse:eclipse” command to get all your
eclipse build path dependencies set automatically. This also means that you can add your
.project & .classpath files under C:tutorialssimple to your source control ignore list and all
you need is your pom.xml file to rebuild (mvn eclipse:clean eclipse:eclipse) it.
12
Also note the source and target folders as shown below:




Open the “App.java” file under “src/main/java” which just prints “Hello World” as shown
below. Also note the “AppTest.java” under “src/test/java” for JUnit testing the “App.java”




You can run this file inside eclipse by right clicking on “App.java” and selecting Run As
Java Application. You should see “Hello World” printed at the console in bottom right hand
corner.
13




The “App.java” will run and print the results in the “Console” window as shown below




        Also note that your class files are generated under “C:tutorialssimpletarget”in an explorer
        window. Now delete all the files under “C:tutorialssimpletarget” for the next step.

        Now, let’s build it as a jar using maven and try to run it outside eclipse (i.e. in a command
        prompt).

        C:tutorialssimple>mvn clean package
14

Now you can see the packaged “simple-1.0-SNAPSHOT.jar” jar file under
“C:tutorialssimpletarget”, in addition to all the class files. The jar file was built based on
your pom.xml file. Now you can run the java application in the command line as follows:


C:tutorialssimple>java -cp .targetsimple-1.0-SNAPSHOT.jar com.mytutorial.App

Results in:
Hello World!

-cp stands for classpath. I.e. where to find your class or classes.
com.mytutorial.App Fully qualified class name.

Note: Lot of beginners make the mistake of not specifying the classpath “-cp”. To know the
syntax of java type C:tutorialssimple>java –help in a command prompt.

This tutorial has given a basic idea of building and running a java application using eclipse
and maven. Now if you want your application to be shared by other applications you can
install them into your maven repository “C:java.m2repository” by:

C:tutorialssimple>mvn install

Now if you go and check under “C:java.m2repository” you should find your package under
C:java.m2repositorycommytutorialsimple1.0-SNAPSHOT.




com.tutorial   is the groupid
simple is the artefact
1.0-SNAPSHOT        is the package version
15
        Open up and check your “pom.xml” (plug-in details are optional) under
        “c:tutorialssimple” as shown below:




References & useful sites:

        Maven home      http://maven.apache.org/

        Maven book http://mavenbook.xwiki.com/xwiki/bin/view/Main/WebHome,
        http://www.devzuz.com/web/guest/products/resources

        Java World Articles http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-
        maven.html, http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html,

        Maven 2 repository    http://repo1.maven.org/maven2/




Please feel free to email any errors to java-interview@hotmail.com. Also stay tuned at
    http://www.lulu.com/java-success for more tutorials and Java/J2EE interview
                                        resources.
16

Tutorial 2 – Java Web, Maven and Eclipse

Now let’s create a simple Web project using maven and eclipse. Download
and install the Tomcat Server site: http://tomcat.apache.org/download-60.cgi
under C:/java.




       Create a skeleton Maven based Web project structure (remember: maven is all about
       “convention over configuration” i.e. consistency) using the following archetype plug-in
       command. Remember that heart of maven is plug-ins and you can look at the syntax for
       different plug-ins at http://maven.apache.org/plugins/index.html.

   C:tutorials>mvn archetype:create -DgroupId=com.mytutorial -DartifactId=simpleWeb
                -DarchetypeArtifactId=maven-archetype-webapp
17
    The above command should have created the following structure in your file system under
    c:/tutorials.




        Now, you need to open up your pom.xml file under C:tutorialssimpleWeb in a note pad
        and add the following lines in bold to give the WTP (Web Tools Platform) support.

<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/maven-
    v4_0_0.xsd">

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mytutorial</groupId>
        <artifactId>simpleWeb</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>simpleWeb Maven Webapp</name>
        <url>http://maven.apache.org</url>
        <dependencies>
                  <dependency>
                          <groupId>junit</groupId>
                          <artifactId>junit</artifactId>
                          <version>3.8.1</version>
                          <scope>test</scope>
                  </dependency>
        </dependencies>
        <build>
                  <finalName>simpleWeb</finalName>
                  <pluginManagement>
                          <plugins>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-compiler-plugin</artifactId>
                                            <version>2.0.2</version>
                                            <configuration>
                                                      <source>1.5</source>
18
                                                     <target>1.5</target>
                                            </configuration>
                                    </plugin>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-eclipse-plugin</artifactId>
                                            <version>2.4</version>
                                            <configuration>
                                                     <downloadSources>false</downloadSources>
                                                     <wtpversion>1.5</wtpversion>
                                            </configuration>
                                    </plugin>
                            </plugins>
                    </pluginManagement>
         </build>
</project>


        Next generate eclipse files by:

    C:tutorials>cd simpleWeb
    C:tutorialssimpleWeb>mvn eclipse:eclipse

    You can notice that .project , & .classpath files and .settings folder have been created under
    C:tutorialssimpleWeb.

        Now get back into your eclipse and import the simpleWeb project in by selecting File
        Import




    Click “Next”.
19




Click “Finish”. Now you should have the simpleWeb project in your workspace.
20

Note: Please note that the project simpleWeb has a world icon next to it along with “J” for java,
to indicate that it is a web project. You could also check this by right clicking on simpleWeb
project then selecting properties Project Facets, which says Java version 5.0 & Dynamic Web
Module Version 2.4.

Important: If you see any errors against simpleWeb then try running the following command in a
command prompt and then refresh your simpleWeb project within eclipse by right clicking and
then selecting “Refresh” or F5.

C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse

Note: The above command will clean (i.e. delete) it first and then rebuild the eclipse files. This
means that you don’t have to check-in these eclipse related files and folders into your source
control. You can add these .project, .classpath and .settings files/folder under
“c:/tutorials/simpleWeb” to the cvs or subversion ignore list.


    Now let’s set up the Tomcat to run inside eclipse by Window        Preferences

Click “Add”




Select “Apache Tomcat V6” and click “Next”
21




Select the “Tomcat Installation Directory” and click “Finish” and then “Ok”.

    Deploy the package into Tomcat Server by: right clicking on the server and then selecting
    “Add and Remove Projects”.
22




Start the Tomcat Server by right clicking on the server inside the server tab and then selecting
“Start”
23




Now finally to run the index.jsp, right click on it and select “Run As” and then “Run On
Server”.
24




Select the server on the next dialog and now you should see:




Alternatively you can type the following URL http://localhost:8080/simpleWeb/index.jsp
in a an instance of the Internet browser outside eclipse and you should see:
25




    Now stop the server inside eclipse by right clicking on it and then selecting stop.




    Now let’s see how to package this war file outside eclipse and deploy it to Tomcat server. To
    package it using maven run:

    C:tutorialssimpleWeb>mvn package

You can open up a file explorer and check for the presence of the packaged “war” file as shown
below.
26




    Now copy your “simpleWeb.war” file into the Tomcat’s “webapps” folder as shown below:




    Now you can start your Tomcat server as a service or from a command prompt as shown
    below:

C:javaTomcat6.0bin>tomcat6.exe
27
        After the server has started , you can type the following URL
        http://localhost:8080/simpleWeb/index.jsp in an instance of the Internet browser outside
        eclipse and you should see:




    Note: It is also worth opening the “simpleWeb.war” file and noting down the packaging structure
    for a “war” (i.e. Web ARchive file) file




References & useful sites:

        Maven home      http://maven.apache.org/

        Maven book http://mavenbook.xwiki.com/xwiki/bin/view/Main/WebHome,
        http://www.devzuz.com/web/guest/products/resources

        Java World Articles http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-
        maven.html, http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html,

        Maven 2 repository    http://repo1.maven.org/maven2/




Please feel free to email any errors to java-interview@hotmail.com. Also stay tuned at
    http://www.lulu.com/java-success for more tutorials and Java/J2EE interview
                                        resources.
28
Tutorial 3 – JSF, Maven and Eclipse

This tutorial is a continuation of the Tutorial 2. We will be using JSF to extend the
simpleWeb project.

        Open your maven’s pom.xml inside eclipse by double clicking on it and add all the
        dependencies for Sun’s JSF RI, Apache commons etc marked in bold. By adding these
        dependencies you tell maven to download these dependency “jar” files for you. Maven
        identifies these jar files based on groupid:artifactid:version.

<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/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion>
 <groupId>com.mytutorial</groupId>
 <artifactId>simpleWeb</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>simpleWeb Maven Webapp</name>
 <url>http://maven.apache.org</url>

  <dependencies>
       <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>3.8.1</version>
               <scope>test</scope>
       </dependency>

        <dependency>
               <groupId>javax.faces</groupId>
               <artifactId>jsf-api</artifactId>
               <version>1.2_02</version>                     Sun’s JSF RI API &
        </dependency>                                        implementation jars
        <dependency>
               <groupId>javax.faces</groupId>
               <artifactId>jsf-impl</artifactId>
               <version>1.2-b19</version>
        </dependency>
        <dependency>
               <groupId>javax.servlet</groupId>
               <artifactId>jstl</artifactId>
               <version>1.1.2</version>
        </dependency>                                        Tag libraries

        <dependency>
               <groupId>taglibs</groupId>
               <artifactId>standard</artifactId>
               <version>1.1.2</version>
        </dependency>

        <dependency>
               <groupId>commons-digester</groupId>
               <artifactId>commons-digester</artifactId>
               <version>1.8</version>                                 Apache commons
        </dependency>                                                 libraries

        <dependency>
               <groupId>commons-collections</groupId>
               <artifactId>commons-collections</artifactId>
29
                <version>3.2</version>
         </dependency>

  </dependencies>

  <build>
         <finalName>simpleWeb</finalName>
         <pluginManagement>
           <plugins>
                  <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>2.0.2</version>
                   <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                  </configuration>
                  </plugin>
                  <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-eclipse-plugin</artifactId>
                   <version>2.4</version>
                   <configuration>
                     <downloadSources>false</downloadSources>
                       <wtpversion>1.5</wtpversion>
                     </configuration>
                  </plugin>
           </plugins>
         </pluginManagement>
  </build>
</project>

After adding remember to save your pom.xml file in eclipse.

Note: Now, you may ask how did I find out the groupid:artifactid:version combination. You can do
this by looking at the dependency jar’s pom.xml files in the maven repository at
http://repo1.maven.org/. For example let’s take the jsf-api & jsf-impl jar files, which can be found at:




Now, if you drill into this, you will find the “pom” files, and if you open it you should be able to find
its coordinates in terms of groupid:artifactid:version. Let’s try this for jsf-api.
30




The groupid:artifactid:version forms the coordinates to identify a particular jar in the maven
repository or your local repository C:java.m2repository.




Note: If a particular dependency jar in your pom.xml file is not found in the local repository
c:java.m2repository, maven 2 will download this from its repository at
http://repo1.maven.org/maven2. Isn’t this a better way to manage your dependency jars rather than
you having to manually download it and check all this into your source control and maintain all the
versions etc?
31
        Next step is to bring in all these dependency jars into the eclipse Java Build Path. If you right
        click on your simpleWeb and then select “Properties” from the pop-up menu, you should see
        the following screen:




    Now, you need to go back to the command prompt and run the following command:

     C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse

    After finish running the above command, go back to your eclipse and refresh the simpleWeb
    project and check your “Java Build Path” again. Now you can see all the jar files added to your
    local repository “C:java.m2repository” with the same coordinates in your pom.xml under
    “c:tutorialssimpleWeb” also the “Java Build Path” updated as shown below. This is the power
    of maven 2!!!.




So far we have got all our dependency jars for JSF downloaded and installed. Next we will build a
simple JSF based Website.
32
    Create a new “java” folder under “simpleWeb/src/main” for all our java files.




Click “Finish”. Now you need to run the following command again from a command prompt.
33
C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse


    Refresh the “simpleWeb” project by selecting it and pressing F5. Now we need to add a java
    package under the “java” folder we just created.
34




Create a package called “com.mytutorial” under “simpleWeb/src/main/java”
35
        Also create the same package under “simpleWeb/src/main/resources”.




        We now need to add a java class and a .properties file under the package “com.mytutorial” we
        created above. Let’s add the messages.properties file first as shown below under
        “simpleWeb/src/main/resources/com/mytutorial”:



Important: According to Maven convention all the java files should go under src/main/java and all
the resources like .properties files should go under src/main/resources folder. When they are
packaged (i.e. war file), both the packages end up under “WEB-INFclasses” folder as a single
package.


        Next step is to create a properties file named “messages.properties” under
        “simpleWeb/src/main/resources/com/mytutorial”
36
37




Open the “messages.properties” file you just added and add the following name/value pairs and then
save the file.

inputname_header=JSF Tutorial
prompt=Tell me your name:
greeting_text=Welcome to JSF
button_text=Hello
sign=!
38




Next step is to create a backing bean java class named “PersonBean.java” under
simpleWeb/src/main/java/com/mytutorial.
39
40




Open the “PersonBean.java” and type the following in bold:


package com.mytutorial;

public class PersonBean {

    String personName;
}
41




Now select the PersonBean.java and generate getter/setter methods for the “personName” as shown
below.
42




Now you should have the following code under PersonBean.java and “Save” the file.

package com.mytutorial;

public class PersonBean {


    String personName;

    public String getPersonName() {
           return personName;
    }

    public void setPersonName(String personName) {
           this.personName = personName;
    }
}
43




Note: “*” in “PersonBean.java” means not yet saved. So remember to save it by clicking the “disk”
icon circled above.

Now you need to run the following command in a command prompt.

C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse

Also refresh the “simpleWeb” project inside eclipse.

Important: According to Maven convention all the java files should go under src/main/java and all
the resources like .properties files should go under src/main/resources folder. When they are
packaged (i.e. war file), both the “PersonBean.class” & “messages.properties” end up under “WEB-
INFclassescommytutorial” folder as shown below.




Next step is to create the JSP pages.
44

        Now add a new folder named “pages” under the “webapp” as shown below:




We will add two JSP files as show below under the “pages” folder we just created.
45




Open the “inputname.jsp” file and type the following code and save it:
46


<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:loadBundle basename="com.mytutorial.messages" var="msg" />

<html>                                 Using your messages.properties file resource bundle
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
         <h3>
         <h:form id="helloForm">                           Using PersonBean.java. Refer faces-
                                                           config.xml for mapped name.
          <h:outputText value="#{msg.prompt}"/>
          <h:inputText value="#{personBean.personName}" />
          <h:commandButton action="greeting" value="#{msg.button_text}" />
        </h:form>
        </h3>
</f:view>                                Using navigation-rule outcome from the
</body>                                  faces-config.xml file
</html>



Follow the same procedures shown above to add another JSP file named greeting.jsp with the
following code.

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:loadBundle basename="com.mytutorial.messages" var="msg" />

<html>
 <head>
         <title>greeting page</title>
 </head>
 <body>
   <f:view>
         <h3>
            <h:outputText value="#{msg.greeting_text}" />,
                  <h:outputText value="#{personBean.personName}" />
        <h:outputText value="#{msg.sign}" />
         </h3>
   </f:view>
</body>
</html>
47




Next step is to create the deployment descriptor files like “faces-config.xml” and “web.xml”.

Q. What are deployment descriptor files?

Deployment descriptors are text-based XML files whose elements describe how to deploy and
assemble components into a specific environment. They also contain information about the components
that can specify settings not contained in the code of the components themselves, such as initialization
parameters and security settings.



         Next we need to add the JSF descriptor file “faces-config.xml” under
         “simpleWeb/src/main/webapp/WEB-INF” with the managed beans e.g. “PersonBean.java”
         and the page navigation logic for the pages “inputname.jsp” and “greeting.jsp”.
48
49
50

The faces-config.xml file should have the following managed beans and navigation rules.


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE faces-config PUBLIC
 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
 "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
        <navigation-rule>                                                     commandButton
                <from-view-id>/pages/inputname.jsp</from-view-id>             action=”greeting”
                <navigation-case>                                             from inputname.jsp
                         <from-outcome>greeting</from-outcome>
                         <to-view-id>/pages/greeting.jsp</to-view-id>
                </navigation-case>
        </navigation-rule>

         <managed-bean>
                <managed-bean-name>personBean</managed-bean-name>
                <managed-bean-class> </managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
         </managed-bean>
</faces-config>




        Next we need to modify the java web descriptor file web.xml with the JSF configuration
        details as shown below.

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
       <context-param>
               <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
               <param-value>server</param-value>
       </context-param>
51

        <context-param>
                <param-name>javax.faces.CONFIG_FILES</param-name>
                <param-value>/WEB-INF/faces-config.xml</param-value>
        </context-param>

        <listener>
                 <listener-class>
                          com.sun.faces.config.ConfigureListener
                 </listener-class>
        </listener>

        <!-- Faces Servlet -->
        <servlet>
                 <servlet-name>Faces Servlet</servlet-name>
                 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                 <load-on-startup>1</load-on-startup>
        </servlet>
                                                                Tells that the URL like *.jsf
                                                                Should use the “Faces
        <!-- Faces Servlet Mapping -->                          Servlet”.
        <servlet-mapping>
                 <servlet-name>Faces Servlet</servlet-name>
                 <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
</web-app>




        Finally modify the index.jsp file as follows before deploying & running:
52

<html>
  <body>
    <jsp:forward page="/pages/inputname.jsf" />
  </body>
</html>




Now you can republish these changes to Tomcat server inside eclipse as follows. After re-
publishing the status should change from “Republish” to “Synchronized”.
53




Start the tomcat server by right clicking on the server and selecting “Start”
Now you can run the index.jsp on the server by selecting it and then “Run As” and “Run On
Server”.
54
55
         You should now get your first screen as follows within eclipse:




Type your name as say “John” in the text box above and click the button “Hello”, you should have the
following screen:




That’s it. You can also stop the server and then build the “war” file outside eclipse with the following
maven command in a command prompt as did before in the Tutorial 2.
56
C:tutorialssimpleWeb>mvn clean package

        Copy the “simpleWeb.war” file under “C:tutorialssimpleWebtarget” to
        “C:javaTomcat6.0webapps”. Start the server by double clicking on “tomcat6.exe” under
        “C:javaTomcat6.0bin”.

        Open an instance of the “Internet Explorer” window type the following URL
        http://localhost:8080/simpleWeb/index.jsp


Note: Unpack your war file and examine the packaged structure:

Library files:




Class/properties files:




Web resource files:
57
Deployment descriptor files:




Manifest file:




That’s all to it. This JSF tutorial is based on the tutorial “JSF KickStart: A Simple
JavaServer Faces Application” at http://www.exadel.com/tutorial/jsf/jsftutorial-
kickstart.html by Exadel, Inc.




Please feel free to email any errors to java-interview@hotmail.com. Also stay tuned at
    http://www.lulu.com/java-success for more tutorials and Java/J2EE interview
                                        resources.
58
                                             Appendix

Sample pom.xml file with plug-ins defined:

<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/maven-v4_0_0.xsd">

       <modelVersion>4.0.0</modelVersion>
       <groupId>com.mytutorial</groupId>
       <artifactId>simple</artifactId>
       <packaging>jar</packaging>
       <version>1.0-SNAPSHOT</version>
       <name>simple</name>
       <url>http://maven.apache.org</url>
       <dependencies>
                <dependency>
                       <groupId>junit</groupId>
                       <artifactId>junit</artifactId>
                       <version>3.8.1</version>
                       <scope>test</scope>
                </dependency>

                     ...........

       </dependencies>

       ...........

       <build>
                     <pluginManagement>
                         <!-- Building -->
                        <plugins>
                             <plugin>
                                     <groupId>org.apache.maven.plugins</groupId>
                                     <artifactId>maven-compiler-plugin</artifactId>
                                     <version>2.0.2</version>
                                     <configuration>
                                              <source>1.5</source>
                                              <target>1.5</target>
                                     </configuration>
                             </plugin>
                             <plugin>
                                     <groupId>org.apache.maven.plugins</groupId>
                                     <artifactId>maven-help-plugin</artifactId>
                                     <version>2.0.1</version>
                             </plugin>
                             <plugin>
                                     <groupId>org.apache.maven.plugins</groupId>
                                     <artifactId>maven-clean-plugin</artifactId>
                                     <version>2.1.1</version>
                             </plugin>
                             <plugin>
                                     <groupId>org.apache.maven.plugins</groupId>
                                     <artifactId>maven-resources-plugin</artifactId>
                                     <version>2.2</version>
                             </plugin>
                             <plugin>
                                     <groupId>org.apache.maven.plugins</groupId>
                                     <artifactId>maven-surefire-plugin</artifactId>
                                     <version>2.2</version>
59
        <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <forkMode>never</forkMode>
                <excludes>
                   <exclude>**/*AbstractTests.java</exclude>
                </excludes>
        </configuration>
</plugin>

<!-- Packaging -->
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <archive>
                   <manifest>
                         <addDefaultImplementationEntries>
                               true
                          </addDefaultImplementationEntries>
                   </manifest>

                 <addMavenDescriptor>true</addMavenDescriptor>
            </archive>
       </configuration>
       <executions>
           <execution>
                <goals>
                    <goal>test-jar</goal>
                </goals>
            </execution>
       </executions>
       </plugin>
       <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.0.3</version>
                <configuration>
                         <attach>true</attach>
                </configuration>
                <executions>
                         <execution>
                                 <goals>
                                         <goal>jar</goal>
                                 </goals>
                         </execution>
                </executions>
       </plugin>
       <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.1</version>
       </plugin>
       <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-archetype-plugin</artifactId>
                <version>1.0-alpha-4</version>
       </plugin>
       <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.1</version>
       </plugin>
60
                               <plugin>
                                       <groupId>org.apache.maven.plugins</groupId>
                                       <artifactId>maven-deploy-plugin</artifactId>
                                       <version>2.3</version>
                               </plugin>

                               <!-- IDE -->
                               <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-eclipse-plugin</artifactId>
                                        <version>2.4</version>
                                        <configuration>
                                              <downloadSources>false</downloadSources>
                                              <wtpversion>1.5</wtpversion>
                                        </configuration>
                               </plugin>
                               <!--Site -->
                               <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-site-plugin</artifactId>
                                        <version>2.0-beta-5</version>
                               </plugin>
                       </plugins>

                    </pluginManagement>
            </build>
 ...............
</project>

More Related Content

What's hot (20)

Maven tutorial for beginners
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
inTwentyEight Minutes
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
Nilanjan Roy
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
Aravindharamanan S
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
mfrancis
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
Luciano Resende
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
ICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEfaces EE - Enterprise-ready JSF Ajax FrameworkICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEsoftTech
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for future
Arun Gupta
 
Maven
Maven Maven
Maven
Khan625
 
Java and XPages
Java and XPagesJava and XPages
Java and XPages
Patrick Kwinten
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回
haruki ueno
 
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages HeavenIBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
Paul Withers
 
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
BP204 It's Not Infernal: Dante's Nine Circles of XPages HeavenBP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
Michael McGarel
 
Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?
Max Andersen
 
Mavenppt
MavenpptMavenppt
Mavenppt
Surekha Achanta
 
Jsf 2.0 in depth
Jsf 2.0 in depthJsf 2.0 in depth
Jsf 2.0 in depth
SILBURY IT SOLUTIONS GMBH
 
How to be effective with JBoss Developer Studio
How to be effective with JBoss Developer StudioHow to be effective with JBoss Developer Studio
How to be effective with JBoss Developer Studio
Max Andersen
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
Nilanjan Roy
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
mfrancis
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
Luciano Resende
 
ICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEfaces EE - Enterprise-ready JSF Ajax FrameworkICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEfaces EE - Enterprise-ready JSF Ajax Framework
ICEsoftTech
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for future
Arun Gupta
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回
haruki ueno
 
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages HeavenIBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
IBM Connect 2014 BP204: It's Not Infernal: Dante's Nine Circles of XPages Heaven
Paul Withers
 
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
BP204 It's Not Infernal: Dante's Nine Circles of XPages HeavenBP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
Michael McGarel
 
Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?
Max Andersen
 
How to be effective with JBoss Developer Studio
How to be effective with JBoss Developer StudioHow to be effective with JBoss Developer Studio
How to be effective with JBoss Developer Studio
Max Andersen
 

Viewers also liked (20)

Using Maven to build Java & Android program
Using Maven to build Java & Android programUsing Maven to build Java & Android program
Using Maven to build Java & Android program
Mu Chun Wang
 
Installing java, eclipse and maven
Installing java, eclipse and mavenInstalling java, eclipse and maven
Installing java, eclipse and maven
inTwentyEight Minutes
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)
XPERT INFOTECH
 
Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
Pranab Dasgupta
 
Oracle - Introduction
Oracle - IntroductionOracle - Introduction
Oracle - Introduction
CompleteITProfessional
 
KeyLabsTraining - Courses
KeyLabsTraining - CoursesKeyLabsTraining - Courses
KeyLabsTraining - Courses
Chinna Botla
 
Database management system chapter1
Database management system chapter1Database management system chapter1
Database management system chapter1
Pranab Dasgupta
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
Pranab Dasgupta
 
Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)
Robert Scholte
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
Neeraj Singh
 
Maven university-course
Maven university-courseMaven university-course
Maven university-course
Olivier Lamy
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
maha tce
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
Sidney Chen
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
Dushmanta Nath
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
pitchaiah yechuri
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
Shakila Mahjabin
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Using Maven to build Java & Android program
Using Maven to build Java & Android programUsing Maven to build Java & Android program
Using Maven to build Java & Android program
Mu Chun Wang
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)
XPERT INFOTECH
 
Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
Pranab Dasgupta
 
KeyLabsTraining - Courses
KeyLabsTraining - CoursesKeyLabsTraining - Courses
KeyLabsTraining - Courses
Chinna Botla
 
Database management system chapter1
Database management system chapter1Database management system chapter1
Database management system chapter1
Pranab Dasgupta
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
Pranab Dasgupta
 
Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)
Robert Scholte
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
Neeraj Singh
 
Maven university-course
Maven university-courseMaven university-course
Maven university-course
Olivier Lamy
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
maha tce
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
Sidney Chen
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Ad

Similar to Java, Eclipse, Maven & JSF tutorial (20)

Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
Arnaud Héritier
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
Arnaud Héritier
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
Steve Keener
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
Maven basics
Maven basicsMaven basics
Maven basics
Vijay Krishnan Ramaswamy
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh656748
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
InstallationGuide-JavaEclipseAndMaven_v2.pdf
InstallationGuide-JavaEclipseAndMaven_v2.pdfInstallationGuide-JavaEclipseAndMaven_v2.pdf
InstallationGuide-JavaEclipseAndMaven_v2.pdf
priyanshu812596
 
Maven definitive guide
Maven definitive guideMaven definitive guide
Maven definitive guide
virusworm
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
Mithilesh Singh
 
Maven
MavenMaven
Maven
Harshit Choudhary
 
Maven
MavenMaven
Maven
Jyothi Malapati
 
Maven
MavenMaven
Maven
Jyothi Malapati
 
Maven
MavenMaven
Maven
Mallikarjuna G D
 
Maven overview
Maven overviewMaven overview
Maven overview
Yukti Kaura
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
SISTechnologies
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache Maven
Arnaud Héritier
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
Arnaud Héritier
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
Arnaud Héritier
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
Steve Keener
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
InstallationGuide-JavaEclipseAndMaven_v2.pdf
InstallationGuide-JavaEclipseAndMaven_v2.pdfInstallationGuide-JavaEclipseAndMaven_v2.pdf
InstallationGuide-JavaEclipseAndMaven_v2.pdf
priyanshu812596
 
Maven definitive guide
Maven definitive guideMaven definitive guide
Maven definitive guide
virusworm
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
Angel Ruiz
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
SISTechnologies
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache Maven
Arnaud Héritier
 
Ad

More from Raghavan Mohan (15)

Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11
Raghavan Mohan
 
Who is BIRT
Who is BIRTWho is BIRT
Who is BIRT
Raghavan Mohan
 
Introduction to BIRT
Introduction to BIRTIntroduction to BIRT
Introduction to BIRT
Raghavan Mohan
 
Sachin Tendulkar Resume
Sachin Tendulkar ResumeSachin Tendulkar Resume
Sachin Tendulkar Resume
Raghavan Mohan
 
Manmohan Singh Resume
Manmohan Singh ResumeManmohan Singh Resume
Manmohan Singh Resume
Raghavan Mohan
 
Senator Barrack Obama Resume
Senator Barrack Obama ResumeSenator Barrack Obama Resume
Senator Barrack Obama Resume
Raghavan Mohan
 
Java/J2EE CV Guide
Java/J2EE CV GuideJava/J2EE CV Guide
Java/J2EE CV Guide
Raghavan Mohan
 
Java/J2EE Companion
Java/J2EE CompanionJava/J2EE Companion
Java/J2EE Companion
Raghavan Mohan
 
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorialHibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Raghavan Mohan
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Raghavan Mohan
 
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorialsSpring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Raghavan Mohan
 
Fast Track to Ajax.
Fast Track to Ajax.Fast Track to Ajax.
Fast Track to Ajax.
Raghavan Mohan
 
23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php
Raghavan Mohan
 
Quality - Douglas Crockford
Quality - Douglas CrockfordQuality - Douglas Crockford
Quality - Douglas Crockford
Raghavan Mohan
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 
Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11
Raghavan Mohan
 
Sachin Tendulkar Resume
Sachin Tendulkar ResumeSachin Tendulkar Resume
Sachin Tendulkar Resume
Raghavan Mohan
 
Senator Barrack Obama Resume
Senator Barrack Obama ResumeSenator Barrack Obama Resume
Senator Barrack Obama Resume
Raghavan Mohan
 
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorialHibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Raghavan Mohan
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Raghavan Mohan
 
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorialsSpring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Raghavan Mohan
 
23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php
Raghavan Mohan
 
Quality - Douglas Crockford
Quality - Douglas CrockfordQuality - Douglas Crockford
Quality - Douglas Crockford
Raghavan Mohan
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 

Recently uploaded (20)

Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 

Java, Eclipse, Maven & JSF tutorial

  • 1. 1 The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The author will not be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Java, Eclipse, Maven & JSF tutorial Maven 2 is a powerful tool that promotes convention over configuration and you need to integrate it into one of the popular integrated development environments (IDEs) called eclipse to make your work easier, thus increasing your productivity and project quality. This tutorial provides an example of how to make Maven and Eclipse collaborate. Also covers the popular JSF Web framework. by K. Arulkumaran & A. Sivayini Website: http://www.lulu.com/java-success Feedback email: [email protected]
  • 2. 2 Table Of Contents Notations ..................................................................................................................... 3 Tutorial 1 – Java, Maven and Eclipse .................................................................. 4 Tutorial 2 – Java Web, Maven and Eclipse....................................................... 16 Tutorial 3 – JSF, Maven and Eclipse.................................................................. 28 Appendix ................................................................................................................... 58
  • 3. 3 Notations Command prompt: Eclipse: File Explorer or Windows Explorer: Internet Explorer:
  • 4. 4 Tutorial 1 – Java, Maven and Eclipse This tutorial will guide you through building a simple Java application from scratch using popular tools like eclipse and maven. This tutorial will be handy for those who are new to maven/eclipse/Java. Install the following programs. In this tutorial I have installed them under c:/java. Java 1.5 (JDK1.5 & JRE1.5) site: http://java.sun.com/javase/downloads/index_jdk5.jsp. . Also set the environment properties JAVA_HOME (e.g. C:javajdk1.5.0) and add to the path (e.g. %JAVA_HOME%bin). If installed correctly you should be able to test it by opening a command prompt and typing C:>java –version Results in: java version "1.5.0_11" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03) Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing) Maven 2.0.7. Site: http://maven.apache.org/download.html. Set the environment variables M2_HOME (e.g. C:javamaven-2.0.7) and add to the path (e.g. %M2_HOME%bin). If installed correctly you should be able to test it by opening a command prompt and typing: C:>mvn --version Results in: Maven version: 2.0.7 Java version: 1.5.0_11 OS name: "windows xp" version: "5.1" arch: "x86" Open the “settings.xml” file under C:javamaven-2.0.7conf folder and set your local repository as follows: <localRepository>C:/java/.m2/repository</localRepository> Also if your internet access is through a proxy server then configure your proxy server in “settings.xml” for example: <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>webproxy</host> <port>8080</port> <nonProxyHosts>local.net,some.host.com</nonProxyHosts> </proxy> Eclipse 3.3.0 (Europa). Site: http://www.eclipse.org/downloads/ So far we have installed the programs under c:/java. Now we need to create a folder for our tutorials as c:/tutorials. Also create an eclipse workspace “C:javaeclipse-tutorial-
  • 5. 5 workspace” where metadata get stored. It is the best practice to separate IDE specific (i.e. C:javaeclipse-tutorial-workspace) files from the projects (i.e. c:/tutorials) specific files. C:/java folder C:/tutorials folder
  • 6. 6 Now let’s have maven into play. One of the powers of maven is its principle of “convention over configuration”. You can run the following command to create a maven project structure. C:tutorials>mvn archetype:create -DgroupId=com.mytutorial -DartifactId=simple The above command results in some directories & files created under c:/tutorials. E.g. C:tutorialssimple project called “simple” C:tutorialssimplesrc “src” folder under which you have “main” & “test” etc. C:tutorialssimplepom.xml the basic maven Project Object Model file. Important (optional step): The plug-ins attached to lifecycle phases should be downloaded and stored automatically (i.e. without having to declare them in pom.xml) exactly at the moment they are needed. For example, if you call mvn compile from the command line. The plugins that you call from the command line are downloaded and stored in the local repository only when you call them (i.e. exactly when you type the command in the command line) even if they are configured in your pom.xml. You can also explicitly define the plug-ins and their version numbers in your pom.xml file as shown below in bold directly under the root element (i.e. <project>). <project ………….> …………………. <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.4</version> <configuration> <downloadSources>false</downloadSources> <wtpversion>1.5</wtpversion> </configuration> </plugin> </plugins> </pluginManagement> </build> …………………. </project> Note: Maven is a plug-in execution framework. You can look for available plug-ins at http://maven.apache.org/plugins/. You can add this plug-ins as required. So if you have any issue(s) in automatically downloading (e.g. due to metadata files getting corrupted) or you want to override any plug-in configuration then use the above mentioned optional-step. Refer appendix for sample pom.xml with other plugins added. Note: You need to have an internet connection so that maven can download the plug-ins from its central repository at http://repo1.maven.org/ (especially http://repo1.maven.org/maven2/ ). The above mentioned plug-ins are based on their groupId under http://repo1.maven.org/maven2/org/apache/maven/plugins/. Note: You can find the documentation on plug-ins at mave2 home site http://maven.apache.org/plugins/index.html.
  • 7. 7 The pom.xml file with plug-in details (plug-in-details are optional) Open up eclipse with workspace: C:javaeclipse-tutorial-workspace. Close the welcome screen and you should get an empty workbench.
  • 8. 8 Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set. Exit out of eclipse and execute the following command in a command prompt. The following command will be making use of the maven-eclipse-plugin. C:tutorials>mvn -Declipse.workspace=C:javaeclipse-tutorial-workspace eclipse:add- maven-repo Results in: [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ---------------------------------------------------------------------------- [INFO] Building Maven Default Project [INFO] task-segment: [eclipse:add-maven-repo] (aggregator-style) [INFO] ---------------------------------------------------------------------------- [INFO] [eclipse:add-maven-repo] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 second [INFO] Finished at: Wed Aug 01 13:38:15 EST 2007 [INFO] Final Memory: 3M/6M [INFO] ------------------------------------------------------------------------ After executing this command, you open up your eclipse and check if this variable M2_REPO has been added. Important: If you had eclipse open while executing the above mvn command you would not see this class path variable M2_REPO (e.g. C:/java/.m2/repository). In eclipse under Window Preferences
  • 9. 9 Note: Alternatively you can manually add this directly into eclipse without having to run the mvn command shown above. If you have a simple java project which is made up of only one module, using eclipse is very simple. Now let us put the eclipse plug-in to the test of generating eclipse metadata (i.e. .project, .classpath files). To generate the eclipse metadata files from your pom.xml you execute the following command: C:tutorials> cd simple C:tutorialssimple>mvn eclipse:eclipse After running this command if you check your local maven repository folder C:java.m2repository should have some dependency jars downloaded from the maven repository site http://repo1.maven.org/maven2 and installed into your local repository C:java.m2repository. Also under your project C:tutorialssimple, you should have some eclipse related files created like .project and .classpath. Note: You can find your downloaded plug-ins in your local repository “C:/java/.m2/repository” which you set earlier in your settings.xml file under %M2_HOME%conf (i.e. C:javamaven-2.0.7conf) Now you get back to your eclipse and import this “simple” project as shown below. File Import.
  • 10. 10 Click “Next”. Click “Finish”. Now you should have the project in eclipse.
  • 11. 11 The “mvn eclipse:eclipse” command also has automatically added build dependencies into your eclipse as shown below by using the M2_REPO class variable, which we set earlier using “mvn -Declipse.workspace=C:javaeclipse-tutorial-workspace eclipse:add-maven- repo” command. Isn’t that cool. You can add any additional dependencies into your “pom.xml” file and then run “mvn eclipse:clean eclipse:eclipse” command to get all your eclipse build path dependencies set automatically. This also means that you can add your .project & .classpath files under C:tutorialssimple to your source control ignore list and all you need is your pom.xml file to rebuild (mvn eclipse:clean eclipse:eclipse) it.
  • 12. 12 Also note the source and target folders as shown below: Open the “App.java” file under “src/main/java” which just prints “Hello World” as shown below. Also note the “AppTest.java” under “src/test/java” for JUnit testing the “App.java” You can run this file inside eclipse by right clicking on “App.java” and selecting Run As Java Application. You should see “Hello World” printed at the console in bottom right hand corner.
  • 13. 13 The “App.java” will run and print the results in the “Console” window as shown below Also note that your class files are generated under “C:tutorialssimpletarget”in an explorer window. Now delete all the files under “C:tutorialssimpletarget” for the next step. Now, let’s build it as a jar using maven and try to run it outside eclipse (i.e. in a command prompt). C:tutorialssimple>mvn clean package
  • 14. 14 Now you can see the packaged “simple-1.0-SNAPSHOT.jar” jar file under “C:tutorialssimpletarget”, in addition to all the class files. The jar file was built based on your pom.xml file. Now you can run the java application in the command line as follows: C:tutorialssimple>java -cp .targetsimple-1.0-SNAPSHOT.jar com.mytutorial.App Results in: Hello World! -cp stands for classpath. I.e. where to find your class or classes. com.mytutorial.App Fully qualified class name. Note: Lot of beginners make the mistake of not specifying the classpath “-cp”. To know the syntax of java type C:tutorialssimple>java –help in a command prompt. This tutorial has given a basic idea of building and running a java application using eclipse and maven. Now if you want your application to be shared by other applications you can install them into your maven repository “C:java.m2repository” by: C:tutorialssimple>mvn install Now if you go and check under “C:java.m2repository” you should find your package under C:java.m2repositorycommytutorialsimple1.0-SNAPSHOT. com.tutorial is the groupid simple is the artefact 1.0-SNAPSHOT is the package version
  • 15. 15 Open up and check your “pom.xml” (plug-in details are optional) under “c:tutorialssimple” as shown below: References & useful sites: Maven home http://maven.apache.org/ Maven book http://mavenbook.xwiki.com/xwiki/bin/view/Main/WebHome, http://www.devzuz.com/web/guest/products/resources Java World Articles http://www.javaworld.com/javaworld/jw-12-2005/jw-1205- maven.html, http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html, Maven 2 repository http://repo1.maven.org/maven2/ Please feel free to email any errors to [email protected]. Also stay tuned at http://www.lulu.com/java-success for more tutorials and Java/J2EE interview resources.
  • 16. 16 Tutorial 2 – Java Web, Maven and Eclipse Now let’s create a simple Web project using maven and eclipse. Download and install the Tomcat Server site: http://tomcat.apache.org/download-60.cgi under C:/java. Create a skeleton Maven based Web project structure (remember: maven is all about “convention over configuration” i.e. consistency) using the following archetype plug-in command. Remember that heart of maven is plug-ins and you can look at the syntax for different plug-ins at http://maven.apache.org/plugins/index.html. C:tutorials>mvn archetype:create -DgroupId=com.mytutorial -DartifactId=simpleWeb -DarchetypeArtifactId=maven-archetype-webapp
  • 17. 17 The above command should have created the following structure in your file system under c:/tutorials. Now, you need to open up your pom.xml file under C:tutorialssimpleWeb in a note pad and add the following lines in bold to give the WTP (Web Tools Platform) support. <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/maven- v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mytutorial</groupId> <artifactId>simpleWeb</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simpleWeb Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>simpleWeb</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source>
  • 18. 18 <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.4</version> <configuration> <downloadSources>false</downloadSources> <wtpversion>1.5</wtpversion> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> Next generate eclipse files by: C:tutorials>cd simpleWeb C:tutorialssimpleWeb>mvn eclipse:eclipse You can notice that .project , & .classpath files and .settings folder have been created under C:tutorialssimpleWeb. Now get back into your eclipse and import the simpleWeb project in by selecting File Import Click “Next”.
  • 19. 19 Click “Finish”. Now you should have the simpleWeb project in your workspace.
  • 20. 20 Note: Please note that the project simpleWeb has a world icon next to it along with “J” for java, to indicate that it is a web project. You could also check this by right clicking on simpleWeb project then selecting properties Project Facets, which says Java version 5.0 & Dynamic Web Module Version 2.4. Important: If you see any errors against simpleWeb then try running the following command in a command prompt and then refresh your simpleWeb project within eclipse by right clicking and then selecting “Refresh” or F5. C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse Note: The above command will clean (i.e. delete) it first and then rebuild the eclipse files. This means that you don’t have to check-in these eclipse related files and folders into your source control. You can add these .project, .classpath and .settings files/folder under “c:/tutorials/simpleWeb” to the cvs or subversion ignore list. Now let’s set up the Tomcat to run inside eclipse by Window Preferences Click “Add” Select “Apache Tomcat V6” and click “Next”
  • 21. 21 Select the “Tomcat Installation Directory” and click “Finish” and then “Ok”. Deploy the package into Tomcat Server by: right clicking on the server and then selecting “Add and Remove Projects”.
  • 22. 22 Start the Tomcat Server by right clicking on the server inside the server tab and then selecting “Start”
  • 23. 23 Now finally to run the index.jsp, right click on it and select “Run As” and then “Run On Server”.
  • 24. 24 Select the server on the next dialog and now you should see: Alternatively you can type the following URL http://localhost:8080/simpleWeb/index.jsp in a an instance of the Internet browser outside eclipse and you should see:
  • 25. 25 Now stop the server inside eclipse by right clicking on it and then selecting stop. Now let’s see how to package this war file outside eclipse and deploy it to Tomcat server. To package it using maven run: C:tutorialssimpleWeb>mvn package You can open up a file explorer and check for the presence of the packaged “war” file as shown below.
  • 26. 26 Now copy your “simpleWeb.war” file into the Tomcat’s “webapps” folder as shown below: Now you can start your Tomcat server as a service or from a command prompt as shown below: C:javaTomcat6.0bin>tomcat6.exe
  • 27. 27 After the server has started , you can type the following URL http://localhost:8080/simpleWeb/index.jsp in an instance of the Internet browser outside eclipse and you should see: Note: It is also worth opening the “simpleWeb.war” file and noting down the packaging structure for a “war” (i.e. Web ARchive file) file References & useful sites: Maven home http://maven.apache.org/ Maven book http://mavenbook.xwiki.com/xwiki/bin/view/Main/WebHome, http://www.devzuz.com/web/guest/products/resources Java World Articles http://www.javaworld.com/javaworld/jw-12-2005/jw-1205- maven.html, http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html, Maven 2 repository http://repo1.maven.org/maven2/ Please feel free to email any errors to [email protected]. Also stay tuned at http://www.lulu.com/java-success for more tutorials and Java/J2EE interview resources.
  • 28. 28 Tutorial 3 – JSF, Maven and Eclipse This tutorial is a continuation of the Tutorial 2. We will be using JSF to extend the simpleWeb project. Open your maven’s pom.xml inside eclipse by double clicking on it and add all the dependencies for Sun’s JSF RI, Apache commons etc marked in bold. By adding these dependencies you tell maven to download these dependency “jar” files for you. Maven identifies these jar files based on groupid:artifactid:version. <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mytutorial</groupId> <artifactId>simpleWeb</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simpleWeb Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-api</artifactId> <version>1.2_02</version> Sun’s JSF RI API & </dependency> implementation jars <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-impl</artifactId> <version>1.2-b19</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> </dependency> Tag libraries <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>1.8</version> Apache commons </dependency> libraries <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId>
  • 29. 29 <version>3.2</version> </dependency> </dependencies> <build> <finalName>simpleWeb</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.4</version> <configuration> <downloadSources>false</downloadSources> <wtpversion>1.5</wtpversion> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> After adding remember to save your pom.xml file in eclipse. Note: Now, you may ask how did I find out the groupid:artifactid:version combination. You can do this by looking at the dependency jar’s pom.xml files in the maven repository at http://repo1.maven.org/. For example let’s take the jsf-api & jsf-impl jar files, which can be found at: Now, if you drill into this, you will find the “pom” files, and if you open it you should be able to find its coordinates in terms of groupid:artifactid:version. Let’s try this for jsf-api.
  • 30. 30 The groupid:artifactid:version forms the coordinates to identify a particular jar in the maven repository or your local repository C:java.m2repository. Note: If a particular dependency jar in your pom.xml file is not found in the local repository c:java.m2repository, maven 2 will download this from its repository at http://repo1.maven.org/maven2. Isn’t this a better way to manage your dependency jars rather than you having to manually download it and check all this into your source control and maintain all the versions etc?
  • 31. 31 Next step is to bring in all these dependency jars into the eclipse Java Build Path. If you right click on your simpleWeb and then select “Properties” from the pop-up menu, you should see the following screen: Now, you need to go back to the command prompt and run the following command: C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse After finish running the above command, go back to your eclipse and refresh the simpleWeb project and check your “Java Build Path” again. Now you can see all the jar files added to your local repository “C:java.m2repository” with the same coordinates in your pom.xml under “c:tutorialssimpleWeb” also the “Java Build Path” updated as shown below. This is the power of maven 2!!!. So far we have got all our dependency jars for JSF downloaded and installed. Next we will build a simple JSF based Website.
  • 32. 32 Create a new “java” folder under “simpleWeb/src/main” for all our java files. Click “Finish”. Now you need to run the following command again from a command prompt.
  • 33. 33 C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse Refresh the “simpleWeb” project by selecting it and pressing F5. Now we need to add a java package under the “java” folder we just created.
  • 34. 34 Create a package called “com.mytutorial” under “simpleWeb/src/main/java”
  • 35. 35 Also create the same package under “simpleWeb/src/main/resources”. We now need to add a java class and a .properties file under the package “com.mytutorial” we created above. Let’s add the messages.properties file first as shown below under “simpleWeb/src/main/resources/com/mytutorial”: Important: According to Maven convention all the java files should go under src/main/java and all the resources like .properties files should go under src/main/resources folder. When they are packaged (i.e. war file), both the packages end up under “WEB-INFclasses” folder as a single package. Next step is to create a properties file named “messages.properties” under “simpleWeb/src/main/resources/com/mytutorial”
  • 36. 36
  • 37. 37 Open the “messages.properties” file you just added and add the following name/value pairs and then save the file. inputname_header=JSF Tutorial prompt=Tell me your name: greeting_text=Welcome to JSF button_text=Hello sign=!
  • 38. 38 Next step is to create a backing bean java class named “PersonBean.java” under simpleWeb/src/main/java/com/mytutorial.
  • 39. 39
  • 40. 40 Open the “PersonBean.java” and type the following in bold: package com.mytutorial; public class PersonBean { String personName; }
  • 41. 41 Now select the PersonBean.java and generate getter/setter methods for the “personName” as shown below.
  • 42. 42 Now you should have the following code under PersonBean.java and “Save” the file. package com.mytutorial; public class PersonBean { String personName; public String getPersonName() { return personName; } public void setPersonName(String personName) { this.personName = personName; } }
  • 43. 43 Note: “*” in “PersonBean.java” means not yet saved. So remember to save it by clicking the “disk” icon circled above. Now you need to run the following command in a command prompt. C:tutorialssimpleWeb>mvn eclipse:clean eclipse:eclipse Also refresh the “simpleWeb” project inside eclipse. Important: According to Maven convention all the java files should go under src/main/java and all the resources like .properties files should go under src/main/resources folder. When they are packaged (i.e. war file), both the “PersonBean.class” & “messages.properties” end up under “WEB- INFclassescommytutorial” folder as shown below. Next step is to create the JSP pages.
  • 44. 44 Now add a new folder named “pages” under the “webapp” as shown below: We will add two JSP files as show below under the “pages” folder we just created.
  • 45. 45 Open the “inputname.jsp” file and type the following code and save it:
  • 46. 46 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <f:loadBundle basename="com.mytutorial.messages" var="msg" /> <html> Using your messages.properties file resource bundle <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <f:view> <h3> <h:form id="helloForm"> Using PersonBean.java. Refer faces- config.xml for mapped name. <h:outputText value="#{msg.prompt}"/> <h:inputText value="#{personBean.personName}" /> <h:commandButton action="greeting" value="#{msg.button_text}" /> </h:form> </h3> </f:view> Using navigation-rule outcome from the </body> faces-config.xml file </html> Follow the same procedures shown above to add another JSP file named greeting.jsp with the following code. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <f:loadBundle basename="com.mytutorial.messages" var="msg" /> <html> <head> <title>greeting page</title> </head> <body> <f:view> <h3> <h:outputText value="#{msg.greeting_text}" />, <h:outputText value="#{personBean.personName}" /> <h:outputText value="#{msg.sign}" /> </h3> </f:view> </body> </html>
  • 47. 47 Next step is to create the deployment descriptor files like “faces-config.xml” and “web.xml”. Q. What are deployment descriptor files? Deployment descriptors are text-based XML files whose elements describe how to deploy and assemble components into a specific environment. They also contain information about the components that can specify settings not contained in the code of the components themselves, such as initialization parameters and security settings. Next we need to add the JSF descriptor file “faces-config.xml” under “simpleWeb/src/main/webapp/WEB-INF” with the managed beans e.g. “PersonBean.java” and the page navigation logic for the pages “inputname.jsp” and “greeting.jsp”.
  • 48. 48
  • 49. 49
  • 50. 50 The faces-config.xml file should have the following managed beans and navigation rules. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"> <faces-config> <navigation-rule> commandButton <from-view-id>/pages/inputname.jsp</from-view-id> action=”greeting” <navigation-case> from inputname.jsp <from-outcome>greeting</from-outcome> <to-view-id>/pages/greeting.jsp</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>personBean</managed-bean-name> <managed-bean-class> </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> </faces-config> Next we need to modify the java web descriptor file web.xml with the JSF configuration details as shown below. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param>
  • 51. 51 <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <listener> <listener-class> com.sun.faces.config.ConfigureListener </listener-class> </listener> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> Tells that the URL like *.jsf Should use the “Faces <!-- Faces Servlet Mapping --> Servlet”. <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> </web-app> Finally modify the index.jsp file as follows before deploying & running:
  • 52. 52 <html> <body> <jsp:forward page="/pages/inputname.jsf" /> </body> </html> Now you can republish these changes to Tomcat server inside eclipse as follows. After re- publishing the status should change from “Republish” to “Synchronized”.
  • 53. 53 Start the tomcat server by right clicking on the server and selecting “Start” Now you can run the index.jsp on the server by selecting it and then “Run As” and “Run On Server”.
  • 54. 54
  • 55. 55 You should now get your first screen as follows within eclipse: Type your name as say “John” in the text box above and click the button “Hello”, you should have the following screen: That’s it. You can also stop the server and then build the “war” file outside eclipse with the following maven command in a command prompt as did before in the Tutorial 2.
  • 56. 56 C:tutorialssimpleWeb>mvn clean package Copy the “simpleWeb.war” file under “C:tutorialssimpleWebtarget” to “C:javaTomcat6.0webapps”. Start the server by double clicking on “tomcat6.exe” under “C:javaTomcat6.0bin”. Open an instance of the “Internet Explorer” window type the following URL http://localhost:8080/simpleWeb/index.jsp Note: Unpack your war file and examine the packaged structure: Library files: Class/properties files: Web resource files:
  • 57. 57 Deployment descriptor files: Manifest file: That’s all to it. This JSF tutorial is based on the tutorial “JSF KickStart: A Simple JavaServer Faces Application” at http://www.exadel.com/tutorial/jsf/jsftutorial- kickstart.html by Exadel, Inc. Please feel free to email any errors to [email protected]. Also stay tuned at http://www.lulu.com/java-success for more tutorials and Java/J2EE interview resources.
  • 58. 58 Appendix Sample pom.xml file with plug-ins defined: <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mytutorial</groupId> <artifactId>simple</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>simple</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> ........... </dependencies> ........... <build> <pluginManagement> <!-- Building --> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-help-plugin</artifactId> <version>2.0.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.1.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.2</version>
  • 59. 59 <configuration> <testFailureIgnore>true</testFailureIgnore> <forkMode>never</forkMode> <excludes> <exclude>**/*AbstractTests.java</exclude> </excludes> </configuration> </plugin> <!-- Packaging --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.1</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries> true </addDefaultImplementationEntries> </manifest> <addMavenDescriptor>true</addMavenDescriptor> </archive> </configuration> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.0.3</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-archetype-plugin</artifactId> <version>1.0-alpha-4</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.1</version> </plugin>
  • 60. 60 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.3</version> </plugin> <!-- IDE --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.4</version> <configuration> <downloadSources>false</downloadSources> <wtpversion>1.5</wtpversion> </configuration> </plugin> <!--Site --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>2.0-beta-5</version> </plugin> </plugins> </pluginManagement> </build> ............... </project>