2010年7月6日火曜日

Scala + Maven2 프로젝트 구성

참조URL
- http://scala-tools.org/mvnsites/maven-scala-plugin/
- http://www.scala-lang.org/node/345

pom.xml파일

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.babukuma</groupId>
<artifactId>scala.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>scala.test</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scalaVersion}</version>
</dependency>
</dependencies>

<build>
<!--
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
-->
<!-- 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>
<!-- 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>


디렉토리 구성
- java소스
・src/main/java
・src/test/java (테스트용)
- scala소스
・src/main/scala
・src/test/scala (테스트용)
- resources
・src/main/resources
・src/test/resources (테스트용)



테스트 소스
HelloScala.scala

package com.babukuma.scala

object HelloScala {

def main(args: Array[String]): Unit = {
println("Hello Scala!")

val helloJava = new HelloJava
helloJava.printHelloJava()
}
}


HelloJava.java

package com.babukuma.scala;

public class HelloJava {
public void printHelloJava() {
System.out.println("Hello Java!");
}
}


컴파일과 패키징

$ mvn compile
$ mvn package


실행



$ mvn scala:run -DmainClass=com.babukuma.scala.HelloScala
Hello Scala!
Hello Java!