2010年7月7日水曜日

Scala WebApplication + Maven 프로젝트 구성

Scala WebApplication + Maven 프로젝트 구성

1. WebApplication프로젝트 작성

mvn archetype:create -DgroupId=com.babukuma -DartifactId=Scala.Web -DarchetypeArtifactId=maven-archetype-webapp


2. 디렉토리 구성
 - java소스
  ・src/main/java
  ・src/test/java (테스트용)
 - scala소스
  ・src/main/scala
  ・src/test/scala (테스트용)
 - resources
  ・src/main/resources
  ・src/test/resources (테스트용)
 - WebApplication파일
  ・src/main/webapp
  ・src/test/webapp (테스트용)



3. pom.xml

<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.babukuma</groupId>
<artifactId>Scala.Web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Scala.Web Maven Webapp</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdkVersion>1.6</jdkVersion>
<junitVersion>4.8.1</junitVersion>
<scalaVersion>2.8.0.RC7</scalaVersion>
<scalaPluginVersion>2.12</scalaPluginVersion>
</properties>

<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junitVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<version>1.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scalaVersion}</version>
</dependency>
</dependencies>
<build>
<finalName>Scala.Web</finalName>

<!-- To define the plugin version in your parent POM -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>${scalaPluginVersion}</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdkVersion}</source>
<target>${jdkVersion}</target>
</configuration>
</plugin>

<!-- To use the plugin goals in your POM or parent POM -->
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>${scalaPluginVersion}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>

<!-- To use the report goals in your POM or parent POM -->
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>${scalaPluginVersion}</version>
</plugin>
</plugins>
</reporting>
</project>



4. 테스트용 소스(Servlet)
HelloScalaServlet.scala

package com.babukuma

import javax.servlet.http._

class HelloScalaServlet extends HttpServlet {
override def doGet(request : HttpServletRequest, response : HttpServletResponse) =
response.getWriter().print("Hello Scala")
}


5. web.xml

<!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>
<display-name>Scala Web Application</display-name>
<servlet>
<servlet-name>helloScala</servlet-name>
<servlet-class>com.babukuma.HelloScalaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloScala</servlet-name>
<url-pattern>/helloScala</url-pattern>
</servlet-mapping>
</web-app>


6. 동작확인