Wednesday, April 25, 2012

My first web program with maven

Maven installation steps:

  1.  Install jdk 1.7 and set the class path.
  2. Unzip the to  apache-maven-3.0.4-bin.zip the directory you wish to install maven. The sub directory  apache-maven-3.0.4  will be created from archive in your choosen directory( C:\Program Files\Apache Software Foundation\apache-maven-3.0.4).
  3. Add %JAVA_HOME% variable in your user variables with the value e.g. C:\Program Files\Java\jdk1.7 .
  4. Add  C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin in you "Path" environment variable.
  5. Open a new command prompt and run mvn -v to verify that it is correctly installed



Steps to create build and run a maven project:
  1. Create a project directory where you wants to create the maven project.
  2. Go to that directory via command prompt.
  3. Create project using the command "mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=org.yarlithub.yschool -DartifactId=yschool-mini-vanaja".
  4. Then go to your project directory (yschool-mini-vanaja).
  5. Then run the command with "mvn compile".
  6. This will create a folder target with compile classes.
  7. To run our project we need a web server. For testing purpose we can use jetty. So we need to add a jetty plug-in to maven pom.xml file. Plug-in should be added under build tag.
<project ...>
<dependencies>
<.../
</dependencies>
<build>
<finalName>yschool</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<!--<configuration>-->
<!--<scanIntervalSeconds>10</scanIntervalSeconds>-->
<!--<stopKey>stop</stopKey>-->
<!--<stopPort>9999</stopPort>-->
<!--</configuration>-->
<executions>
<execution>
<id>start-jetty</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </build> </project>


9.    After adding the plug-in run the command  "mvn install jetty:run".
10.  Now Jetty will be start and project will be deployed there.
11.  Now go to your browser and type http://localhost:8080/<project-name>
12.  There will be your page displaying.

No comments:

Post a Comment