This tutorial shows a simple way to get started with a Java web application at Jetty server with maven2 as build tool. Ok, so it’s for Windows but it should not be hard to port the non platform independent commands to other platforms.
1) Install Java
Download a Java Jdk version from http://java.sun.com/javase/downloads/, for example Java SE Development Kit (JDK) 6 Update 11
Install in your preferred location, for example “C:\Java\jdk1.6.0_11\”.
2) Install Maven2
Download apache-maven-2.0.9 (http://maven.apache.org/download.html) and unzip to c:\tools\apache-maven-2.0.9
Create the directories C:\tools\.m2 and c:\tools\.m2\repository
Create the environment variable M2_HOME=C:\tools\apache-maven-2.0.9
Add %M2_HOME%\bin to the environment variable PATH
Create the environment variable M2_REPO=c:\tools\.m2\repository
Create the environment variable JAVA_HOME=C:\Program\Java\jdk1.6.0_11
Add %JAVA_HOME%\bin to the environment variable PATH
Verify maven installation
>mvn -version
Should display something like:
Maven version: 2.0.9
Java version: 1.6.0_11
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
Verify Java version:
>java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
3) Create workspace location
cd to your workspace location (or other of your choice where you wish to add the project) and open a command prompt, for example C:\ws
> cd C:
> mkdir ws
> cd C:\ws
4) Create the maven project
>mvn archetype:create -DgroupId=se.javanews.helloworld -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-webapp
5) Edit pom.xml
Go to helloworld and open pom.xml and add the <plugins> element in the <build> element
<build>
…
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
6) Create deploy shortcut
Create the file deploy.bat with content
@echo off
%M2_HOME%\bin\mvn jetty:run
7) Install application
run
> mvn install
9) Deploy application at Jetty
run
> mvn jetty:run
or
execute deploy.bat (doubleclick)
10) Try it out
Open http://localhost:8080/helloworld/ in a browser at your choice and test the page
Good luck!
Please inform me of any problems or mistakes in this tutorial!
January 23rd, 2009 | Tags: holloworld, java, jetty, maven2 | Category: build tools, development, java, maven | Leave a comment