如何在eclipse中构建scala开发环境

本文介绍了如何在Eclipse中构建Scala开发环境,包括安装Scala、SBT工具,使用SBT创建项目结构,以及配置SBT支持本地Maven和私服。通过这些步骤,开发者可以在Eclipse中管理和编译Scala项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[没打算用idea,就总结下eclipse中如何构建和开发scala项目]

1.基本概念

scala 一种语法。(类似java)  http://www.scala-lang.org/

sbt 一个构建工具。(类似maven,gradle,ant等) http://www.scala-sbt.org/

eclipse 。。这家伙只有scala开发环境的插件,可以构建scala project,但是没有sbt 插件。。就像没有maven插件的eclipse,只能构建和编辑java project,但是整不了maven project.


2.步骤。

@构建Scala语言环境  

和java一样,分两步,下载软件,和配置HOME和Path.

@安装SBT 工具

下载、配置全局变量(在windows环境中添加sbt.bat脚本,可以直接运行)

@使用SBT生成一个类似maven 包结构的scala project

3.实际操作

@新建一个目录叫 test

@在test目录中新建文件build.sbt

@在test目录新建project目录,进入project目录,并新建plugins.sbt,在其中添加 

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0")
@在build.sbt中配置工程的name,scala编译环境,依赖等等。如:

import sbt._
import Process._
import Keys._

EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

lazy val commonSettings = Seq(
	name := "test",
	organization := "com.marsyoung",
	version := "0.0.1-SNAPSHOT",
	scalaVersion := "2.11.7"
)

lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
	libraryDependencies ++=  Seq(
		"junit" % "junit" % "4.4",
		"javax.ws.rs" % "jsr311-api" % "1.1.1"
	)
  )

@在cmd中进入对应的project目录,即test目录。运行sbt。

@执行eclipse命令,将对应的项目转化成可以引入eclipse并且目录结构类似maven的项目。

@打开已经安装了scala ide的eclipse,导入对应的project,会自动的编译成scala peoject.


4.Tips:

SBT配置使其支持本地maven和私服,如下:

在用户根目录下的.sbt文件夹内,在windows下就是C->用户->用户名->.sbt目录下新建repositories文件并插入内容:

[repositories]
  local
  activator-launcher-local: file:${activator.local.repository-${activator.home-${user.home}/.activator}/repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  activator-local: file:${activator.local.repository-D:/maven/repo3.3.1}
  sohu-public: http://xxx.com/nexus/content/groups/public 

  typesafe-releases: http://repo.typesafe.com/typesafe/releases
  typesafe-ivy-releasez: http://repo.typesafe.com/typesafe/ivy-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  sonatype-oss-releases
  sonatype-oss-snapshots
  maven-central

本地maven地址为:

D:/maven/repo3.3.1

nexus私服地址为:

http://xxx.com/nexus/content/groups/public 

有点不爽的是,如果有新的依赖或者包需要引入,在eclipse中不会自动编译,还得手动的去sbt控制台去compile和eclipse。

希望过段时间会有sbt的插件吧。(2015-12-24 )




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值