简体   繁体   English

scala Ide无法将我的班级确定为主要方法

[英]scala Ide Not identifying my class as main method

I have researched some answers in Stackoverflow but my error seems to be different. 我研究了Stackoverflow中的一些答案,但我的错误似乎有所不同。 Having said that i am a newbie in scala hence please consider that as well. 话虽如此,我还是scala的新手,因此也请考虑一下。

I am trying to create multi class project in scala. 我正在尝试在Scala中创建多类项目。 Project Format is like this 项目格式是这样的

Test Project | 测试项目 COM Package | COM包| |-->App.class | |-> App.class | COM.Test Package | COM.Test包| |-->App1.class |-> App1.class

Code Snippet 代码段

App.scala App.scala

object App {

  def main(args : Array[String]): Unit = {
    var logger = Logger.getLogger(this.getClass())
     if (args.length < 3) {
      logger.error("=> wrong parameters number")
      System.err.println("Usage: MainExample <path-to-files> <srcCode> <tableName>")
      System.exit(1)
    }
      println("In Main Class")
}

App1.scala App1.scala

object App1 {

      def main(args : Array[String]): Unit = {
         println("In Sub Class")
    }

Pom.xml Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0</version>
  <name>${project.artifactId}</name>
  <description>My wonderfull scala app</description>
  <inceptionYear>2015</inceptionYear>
  <licenses>
    <license>
      <name>My License</name>
      <url>http://....</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <encoding>UTF-8</encoding>
    <scala.version>2.10.4</scala.version>
    <scala.compat.version>2.10.4</scala.compat.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <!-- >testSourceDirectory>src/test/scala</testSourceDirectory -->
    <!-- plugins>
      <plugin>
        <see http://davidb.github.com/scala-maven-plugin >
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>

            </goals>
            <configuration>
              <args>
                <arg>-make:transitive</arg>
                <arg>-dependencyfile</arg>
                <arg>${project.build.directory}/.scala_dependencies</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins -->
  </build>
</project>

I am using SCALA IDE along with Scala Maven Plugin. 我正在使用SCALA IDE和Scala Maven插件。 I have commented out the build plugin but it doen=s not make a difference if that is turned on as well. 我已经注释掉了构建插件,但是如果将其打开也不会有所作为。

Two Issues i am facing 我面临的两个问题

Issue 1) I am unable to Run App1.scala in Sub Package COM.Test. 问题1)我无法在子包COM.Test中运行App1.scala。 App.scala is run without issue from Run As -->Scala Application. App.scala在运行方式-> Scala应用程序中运行没有问题。 But when ever i try to run App1.scala the scala side is not able to find Main Class 但是,当我尝试运行App1.scala时,scala端无法找到Main Class

Issue 2) I am unable to debug my code for App.scala in scala ide. 问题2)我无法在scala ide中调试App.scala的代码。 Whenever i run Debug Command (Bug Operator) the breakpoints are skipped and code executes entirely. 每当我运行Debug Command(错误操作程序)时,就会跳过断点,并且代码将完全执行。 I use Scala JVM Launcher and checked The option Stop in Main. 我使用Scala JVM启动器,并选中了选项Main in Stop。 Please help 请帮忙

Using Eclipse Luna with Scala IDE and MAC OS 将Eclipse Luna与Scala IDE和MAC OS结合使用

You need to add extends App to your main objects. 您需要向您的主要对象添加extends App

object App  extends App {

  def main(args : Array[String]): Unit = {
    var logger = Logger.getLogger(this.getClass())
     if (args.length < 3) {
      logger.error("=> wrong parameters number")
      System.err.println("Usage: MainExample <path-to-files> <srcCode> <tableName>")
      System.exit(1)
    }
      println("In Main Class")
}

Package structure must correspond to directory structure in the IDE. 包结构必须与IDE中的目录结构相对应。 (This is unlike scalac.) (这与scalac不同。)

It's hard to tell from the info you present, but I can confirm that Scala IDE (on Eclipse Luna) will not offer "Run As > Scala application" if I remove the package declaration. 很难从您提供的信息中看出来,但是我可以确认,如果删除了包声明,Scala IDE(在Eclipse Luna上)将不会提供“运行方式> Scala应用程序”。

For example, if the class App in directory src/p/ (source file src/p/App.scala ) is not in package p , then it won't offer to run it. 例如,如果目录src/p/ (源文件src/p/App.scala )中的App类不在package p ,则它不会提供运行它的src/p/App.scala

Uncommenting the correct package declaration gets the run as menu back. 取消注释正确的软件包声明即可返回run as菜单。

I can also verify that a debug config with stop in main and Scala JVM launcher works as expected for App in the default package as well as in a named package. 我还可以验证stop in mainScala JVM launcher带有stop in main的调试配置是否可以按预期在默认程序包和命名程序包中对App起作用。 So I don't know how that could have broken for you. 因此,我不知道这对您有何影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM