Spiritual java is an attempt to let me express my thoughts, my ideas, my views and my feelings about two topics which are very close to my heart. Vippasana and Java!!! I have been practicing Vipassana for more than 8 years now and in all these years the way this teqnuqie helped me in overcoming many ups and downs in my life is quite remarkable. Java on the other hand is my source of my materialistic existence. So I'll be sharing my views on J2EE technology and its relevance in web.

Saturday 26 September 2009

Creating HelloWorld webapp in Lift and Deploying it on Tomcat 6.x

In this post I'm going to create a very simple webapp on lift and then deploy it on tomcat 6. As usual, I'm going to use mac OsX but it should not be too different on any other environment. The most funny part is that we don't have to write a single line of code to make our Helloworld app! A sample HelloWorld app for lift framework already comes in as Maven build.


So lets get started, first u need to have the following:
  • jdk 1.5 or above installed on ur system. You can download it from here.
  • Latest Maven  installation. You can download it from here.
  • Scala Plugin for eclipse. See how to install it from here.
Once everything is installed go to the command prompt and check mvn version.


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn -version


Maven version: 2.0.9
Java version: 1.5.0_19
OS name: "mac os x" version: "10.5.8" arch: "i386" Family: "unix"
suresh-sharmas-macbook-pro:~ sureshsharma$


This should tell u the maven version installed. Now go to ur workspace directory, in my case it is /Projects


At the command prompt give the following command; I'll explain the
meaning of it a little later.


Suppose I want to create a project called helloworld and want to be
packaged under com.elslon.lancet.rad, then first I'll go to my
workspace /Projects


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn archetype:generate -U \-DarchetypeGroupId=net.liftweb \-DarchetypeArtifactId=lift-archetype-blank \-DarchetypeVersion=1.0 \-DgroupId=com.elslon.lancet.rad \-DartifactId=helloworld \-Dversion=1.0-SNAPSHOT


Once executed it will dispaly a list of outputs in verbose mode. At one or two places you may be prompted, just press enter.


Once it is done and u get back to the command prompt u are ready to  launch your first app. Go to the project directory.


suresh-sharmas-macbook-pro:Projects sureshsharma$ cd helloworld


suresh-sharmas-macbook-pro:helloworld sureshsharma$ ls
pom.xml src
suresh-sharmas-macbook-pro:helloworld sureshsharma$


Maven. Comes in with inbuilt jetty and tomcat plugin so give the following command for tomcat deploy the app using tomcat plugin for maven.


suresh-sharmas-macbook-pro:helloworld sureshsharma$ mvn tomcat:run


And here u go it will start tomcat plugin and u will be able to see it running at http://localhost:8080/


The next step is to create a war file to be deployed on tomcat, go to  helloworld directory, you should see that pom.xml and target directory present there. Give the following command mvn package. This is maven's task that builds and creates the war file and place it in target directory. In our case the war file will be created in /Projects/helloworld/target/helloworld-1.0-SNAPSHOT.war.


Now take the war file and deploy it on tomcat. Start the tomcat and here you go! You have deployed your helloworld lift webapp on tomcat.


No comments:

Post a Comment