如何在sbt,Eclipse和github中初始化新的Scala项目 [英] How to initialize a new Scala project in sbt, Eclipse and github

查看:201
本文介绍了如何在sbt,Eclipse和github中初始化新的Scala项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sbt,Eclipse和github中初始化一个新的Scala项目,以便它们一起播放...

解决方案

一个新的Scala项目通常需要为sbt,eclipse(如果你这样选择)和github设置,这样它们都可以一起工作。在这个设置上投入一些时间后,只要简单的方法不可用,就可能有助于列出这3个工具/服务。以下为我工作的一系列步骤。假设您已经安装了eclipse中的Scala IDE插件。


  1. 创建一个新的repo 在Github

  2. 确定新项目的目录位置

  3. 在eclipse中,使用Git Repositories视图将Github repo导入该位置。另外也可以使用命令行git。

  4. 找到您为项目选择的同一位置,并运行 sbt eclipse 。这样可以确保eclipse能够处理sbt项目结构,以便您的项目可以由sbt构建,同时也可以被eclipse所理解。如果 sbt eclipse 不起作用,sbt eclipse插件可能没有安装在sbt - 安装它

  5. 在eclipse中,使用文件 - >导入 - >一般 - >现有项目进入Workspace ,选择相同的位置,以便eclipse为刚刚由sbt准备的文件结构构建其项目结构。

  6. Make git通过更新.gitignore文件来忽略eclipse和sbt文件,忽略所有新项目的核心。以下似乎目前很好。

      *。class 
    * .log

    #sbt specific
    dist / *
    target /
    lib_managed /
    src_managed /
    project / boot /
    project / plugins / project /

    #Scala-IDE特定
    .scala_dependencies

    #Eclipse特定
    .project
    .classpath
    .cache


您现在应该能够在eclipse中运行项目,而在sbt中,并通过git提交和推送代码更改。要看到空的项目运行,在这个阶段可能很有意义,你可以在eclipse中添加scala类,只包含以下代码。请注意,scala源应通常位于src / main / scala下。如果此路径不存在,请通过以下方式创建。

 对象hello  {
def main(args:Array [String]){
println(Main starting)
}
}
pre>

或者只是这个代码:

  {
println(申请开始)
}


需要放弃eclipse,sbt等的未来版本可能会使这个过时。
如果在您的环境中这是错误的,您可以添加更好的答案。


How to initialize a new Scala project in sbt, Eclipse and github, so that it all plays together...

解决方案

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.

  1. Create a new repo in Github.
  2. Decide a directory location for the new project
  3. In eclipse, use the Git Repositories View to import the Github repo into that location. Alternatively you can use command line git for that.
  4. 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. If sbt eclipse doesn't work, the sbt eclipse plugin is probably not installed in sbt - install it.
  5. 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.
  6. 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
    

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")  
  }
}

Or alternatively only this code:

object app extends App {
  println("Application starting")  
}

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项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆