How to initialize a new Scala project in sbt, Eclipse and github(如何在 sbt、Eclipse 和 github 中初始化一个新的 Scala 项目)
问题描述
如何在 sbt、Eclipse 和 github 中初始化一个新的 Scala 项目,让它们一起玩……
How to initialize a new Scala project in sbt, Eclipse and github, so that it all plays together...
推荐答案
一个新的 Scala 项目通常需要为 sbt、eclipse(如果你选择)和 github 设置,这样它们就可以协同工作.在此设置上投入一些时间后,只要没有更简单的方法可用,拥有此列表以对齐这 3 个工具/服务可能会有所帮助.对我有用的一系列步骤如下.它假定您在 eclipse 中安装了 Scala IDE 插件.
A new Scala project typically requires being set up for sbt, eclipse (if you so choose) and github such that it all works together. After investing some time on this setup, it may help to have this list for aligning these 3 tools/services, for as long as simpler ways are not available. The series of steps that works for me follows. It assumes you have the Scala IDE plugin installed in eclipse.
- 在 Github 中创建一个新的 repo .
- 确定新项目的目录位置
- 在 Eclipse 中,使用 Git 存储库视图将 Github 存储库导入该位置.或者,您可以为此使用命令行 git.
- 找到您为项目选择的同一位置并运行
sbt eclipse
.这确保 eclipse 能够处理 sbt 项目结构,以便您的项目可以由 sbt 构建,同时也可以被 eclipse 理解.如果sbt eclipse
不起作用,可能是 sbt 中没有安装 sbt eclipse 插件 - install它. - 在eclipse中,使用
File -->导入 -->一般 -->Existing Projects into Workspace
,选择相同的位置,以便 eclipse 为 sbt 刚刚准备好的文件结构构建其项目结构. 通过更新 .gitignore 文件以忽略 eclipse 和 sbt 文件,使 git 忽略新项目的核心以外的所有内容.以下似乎目前很好.
- Create a new repo in Github.
- Decide a directory location for the new project
- In eclipse, use the Git Repositories View to import the Github repo into that location. Alternatively you can use command line git for that.
- Locate to that same location you've chosen for the project and run
sbt eclipse
. This makes sure eclipse will be able to handle the sbt project structure, so that your project can be built by sbt while also being intelligible for eclipse. Ifsbt eclipse
doesn't work, the sbt eclipse plugin is probably not installed in sbt - install it. - In eclipse, use
File --> Import --> General --> Existing Projects into Workspace
, selecting that same location, so that eclipse builds its project structure for the file structure having just been prepared by sbt. Make git ignore all but the core of your new project by updating the .gitignore file to ignore eclipse and sbt files. The following seems to be currently fine.
*.class
*.log
# sbt specific
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
# Scala-IDE specific
.scala_dependencies
# Eclipse specific
.project
.classpath
.cache
您现在应该能够在 eclipse 和 sbt 中运行项目,并通过 git 提交和推送代码更改.要查看空项目运行,这在这个阶段可能很有意义,您可以在 eclipse 中添加一个 scala 类,仅包含以下代码.请注意,scala 源代码通常应位于 src/main/scala 下.如果此路径尚不存在,请通过例如创建它mkdir -p src/main/scala
在 Unix 上.
You should now be able to run the project in eclipse, and in sbt, and commit and push code changes through git. To see the empty project run, which may very well make sense at this stage, you can add a scala class in eclipse to it, containing merely the following code. Note that scala sources should typically sit under src/main/scala. If this path doesn't exist yet, create it through e.g. mkdir -p src/main/scala
on Unix.
object hello {
def main(args: Array[String]) {
println("Main starting")
}
}
或者只有这个代码:
object app extends App {
println("Application starting")
}
它现在应该可以工作了.需要声明的是,未来版本的 eclipse、sbt 等可能会使它过时.如果这在您的环境中完全错误,您可以添加更好的答案.
It should work now. Need to disclaim that future versions of eclipse, sbt, etc may render this outdated. If this is dead wrong in your environment, you can add a better answer.
这篇关于如何在 sbt、Eclipse 和 github 中初始化一个新的 Scala 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 sbt、Eclipse 和 github 中初始化一个新的 Scala 项目
基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01