簡體   English   中英

scala Ide無法將我的班級確定為主要方法

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

我研究了Stackoverflow中的一些答案,但我的錯誤似乎有所不同。 話雖如此,我還是scala的新手,因此也請考慮一下。

我正在嘗試在Scala中創建多類項目。 項目格式是這樣的

測試項目 COM包| |-> App.class | COM.Test包| |-> App1.class

代碼段

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

object App1 {

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

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>

我正在使用SCALA IDE和Scala Maven插件。 我已經注釋掉了構建插件,但是如果將其打開也不會有所作為。

我面臨的兩個問題

問題1)我無法在子包COM.Test中運行App1.scala。 App.scala在運行方式-> Scala應用程序中運行沒有問題。 但是,當我嘗試運行App1.scala時,scala端無法找到Main Class

問題2)我無法在scala ide中調試App.scala的代碼。 每當我運行Debug Command(錯誤操作程序)時,就會跳過斷點,並且代碼將完全執行。 我使用Scala JVM啟動器,並選中了選項Main in Stop。 請幫忙

將Eclipse Luna與Scala IDE和MAC OS結合使用

您需要向您的主要對象添加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")
}

包結構必須與IDE中的目錄結構相對應。 (這與scalac不同。)

很難從您提供的信息中看出來,但是我可以確認,如果刪除了包聲明,Scala IDE(在Eclipse Luna上)將不會提供“運行方式> Scala應用程序”。

例如,如果目錄src/p/ (源文件src/p/App.scala )中的App類不在package p ,則它不會提供運行它的src/p/App.scala

取消注釋正確的軟件包聲明即可返回run as菜單。

我還可以驗證stop in mainScala JVM launcher帶有stop in main的調試配置是否可以按預期在默認程序包和命名程序包中對App起作用。 因此,我不知道這對您有何影響。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM