NetBeans+Maven 搭建Scala开发环境

软件以及操作系统要求
下载Netbeans6.9.1 zip版本
下载maven2.2.1<maven3 本人还没有试过>,解压缩,设置路径
下载netbeans scala插件http://sourceforge.net/projects/erlybird/files/nb-scala/6.9v1.1.0/ 下载后安装
详细可以参考:http://wiki.netbeans.org/Scala69
操作系统:UBuntu
注:这里最好使用mac或者linux环境,并且是解压缩版本。windows环境工程大的时候,会有问题。

建立scala工程
文件->新建项目->Maven->Maven项目 两个下一步后,项目名称为scala-test,而后完成
编辑pom.xml文件
添加scala repository
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
添加dependencies
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.8.1</version>
</dependency>
添加pluginRepositories
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
添加build
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

编写代码
新建包scala
添加Object:ListTest
编辑代码
package scala
object ListTest {
val list = List("a","b","c")

def main(args: Array[String]): Unit = {
list match{
case n :: h =>
println("n====" + n)
println("h====" + h.mkString(","))
}
}
}
在maven-scala-plugin中添加测试脚本
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx512m</jvmArg>
<jvmArg>-Xss10m</jvmArg>
</jvmArgs>
<launchers>
<launcher>
<id>list</id>
<mainClass>scala.ListTest</mainClass>
</launcher>
</launchers>
</configuration>
</plugin>
编译运行
cd 到工程根目录下: /home/sujx/NetBeansProjects/scala-test
运行 mvn clean install 第一次因为要下载依赖包,所以会比较慢
测试 mvn scala:run -Dlauncher=list
会在之后的命令行看到如下:
......
[INFO] n====a
[INFO] h====b,c
......
编译成功。

源代码包如下:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值