The Artima Developer Community
Sponsored Link

Web Buzz Forum
Learning Scala : Hello World Web App with SBT

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Chee Seng Chua

Posts: 62
Nickname: quai83
Registered: Nov, 2006

Chee Seng Chua is Senior Application Developer for KZEN Solutions Berhad
Learning Scala : Hello World Web App with SBT Posted: May 7, 2011 7:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Chee Seng Chua.
Original Post: Learning Scala : Hello World Web App with SBT
Feed Title: Chee Seng Tech Blog
Feed URL: http://chuacheeseng.blogspot.com/atom.xml
Feed Description: When you think you are superior, you are being an idiot...
Latest Web Buzz Posts
Latest Web Buzz Posts by Chee Seng Chua
Latest Posts From Chee Seng Tech Blog

Advertisement
Creating Project:-


mkdir HelloWorld
cd HelloWorld
sbt


You will be prompted to create new project, type 'y' and enter project name, organization, version etc.:-


Name: HelloWorld
Organization: QQ Enterprise
Version [1.0]:
Scala version [2.8.1]:
sbt version [0.7.5]:


Required Scala libraries will be downloaded automatically, make sure you are connected to internet.

Create WebAppBuild.scala build in project/build/ (create build directory if it's not there):-


import sbt._
class WebAppBuild(info: ProjectInfo) extends DefaultWebProject(info) {
val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test"
val servletApi = "javax.servlet" % "servlet-api" % "2.5"
}


In the SBT console, enter:-


reload
update


Create HelloWorldServlet.scala in src/main/scala directory:-


import javax.servlet.http._
class HelloWorldServlet extends HttpServlet {
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) = {
resp.getWriter().print("Hello World!")
}
}


Create webapp directory in src/main, and consequently create WEB-INF directory and web.xml:-


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>


In SBT, run:-


reload
jetty-run


Open your web browser and go to http://localhost:8080, you should see the Hello World! message being print out from your simple servlet written in Scala.

Read: Learning Scala : Hello World Web App with SBT

Topic: Facebook CEO Mark Zuckerberg Buys new $7 Million House [Photos] Previous Topic   Next Topic Topic: How to Unlock iPhone 4,3GS Running iOS 4.3.3 Using UltrasnOw 1.2.3

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use