configure run in eclipse for Scala

后端 未结 14 1706
自闭症患者
自闭症患者 2021-01-30 16:03

I am a beginner in Scala. I installed Scala IDE in eclipse and now I want to run my application programme. It never shows \"run as Scala application\", instead it shows \"run

相关标签:
14条回答
  • 2021-01-30 16:24

    Just a pointer .. I had faced same difficulty . Being experienced from JAVA , instead of creating a Spark object I was creating spark class that why I was not getting this option .

    Hope my experience helps .

    0 讨论(0)
  • 2021-01-30 16:26

    Download from this link Scala IDE

    Restart Eclipse, create Scala Project, then create Scala Object and type this.

     package greeter
    
        object Hello {
            def main(args:Array[String]) { 
              println("Hello, World") 
            }   
        }
    

    Run as Scala Application

    0 讨论(0)
  • 2021-01-30 16:30

    I had issues with the Scala IDE for Eclipse running Scala applications that extend Application, but running objects with a proper main method, i.e. def main(args:Array[String]) {/*...*/} always works fine for me.

    0 讨论(0)
  • 2021-01-30 16:35

    If you want to run the whole project it should have a "main class", in any of your Scala objects you should be defining:

    def main(args:Array[String]) { <some nice code here> }
    

    From there it should be "calling" the rest of your objects to do whatever the whole project does and in the "Class Main" column you should specify the fully qualified name of your object. For instance, if you defined the main in a class called "Start" in the package "starter", in the "Class Main" field you should state "starter.Start".

    But on the other hand if you only want to run a Scala object it should extend App, if it doesn't extend App, Scala IDE won't add the "Run as Scala Application...":

    package greeter
    object Hello extends App {
      println("Hello, World!")
    }
    
    0 讨论(0)
  • 2021-01-30 16:37

    Following are the steps that I took to successfully run scala(Ubuntu) on eclipse:
    1. Download Scala IDE
    2. After installation, create a maven project.
    3. right click on the project, go to configure and "Add Scala Nature"
    4. In the .pom I provided the following dependencies:

        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.12</artifactId>
        <version>2.4.1</version>
    </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.12</artifactId>
        <version>2.4.1</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-graphx -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-graphx_2.12</artifactId>
        <version>2.4.1</version>
    </dependency>
    
    1. Ensure that src/main/scala is on the build path.
    2. Create a scala file to test your project.

    Hope this helps!!!

    0 讨论(0)
  • 2021-01-30 16:41

    Right click your project and check the "Scala Compiler" settings. Check the "Project Specific" checkbox and try checking if you can run your Scala object (which should extend App).

    0 讨论(0)
提交回复
热议问题