我在Stackoverflow中研究了一些答案,但我的错误似乎有所不同。虽然我说我是斯卡拉的新手因此也请考虑一下。
我正在尝试在scala中创建多类项目。项目格式是这样的
测试项目 | COM包 | | - > App.class | COM.Test Package | | - > 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。运行方式 - &gt; Scala应用程序运行App.scala没有问题。但是当我尝试运行App1.scala时,scala端无法找到Main Class
问题2)我无法在scala ide中调试App.scala的代码。每当我运行Debug Command(Bug Operator)时,都会跳过断点并完全执行代码。我使用Scala JVM Launcher并选中了Stop in Main选项。请帮忙
将Eclipse Luna与Scala IDE和MAC OS一起使用
答案 0 :(得分:0)
您需要将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")
}
答案 1 :(得分:0)
包结构必须与IDE中的目录结构相对应。 (这与scalac不同。)
很难从您提供的信息中了解到,但我可以确认,如果删除软件包声明,Scala IDE(在Eclipse Luna上)将不会提供“Run As&gt; Scala应用程序”。
例如,如果目录App
中的类src/p/
(源文件src/p/App.scala
)不在package p
中,那么它将无法运行它。< / p>
取消注释正确的包声明会返回run as
菜单。
我还可以验证stop in main
和Scala JVM launcher
的调试配置是否与默认包中的App
以及命名包中的预期一致。所以我不知道那对你来说有什么打破。