我试图使用maven来处理Eclipse中的scala项目中的依赖项 . 但是一旦项目转换为maven,应用程序就不再运行了 .
以下是重现的步骤:
1)新的scala项目
-
项目名称:测试
-
完成
2)新的scala对象
-
name:hello_world
-
完成
3)hello_world.scala
package test
object hello_world {
def main(args: Array[String]) {
println("Hello world !!!")
}
}
4)运行scala应用程序
-
项目:测试
-
主类:test.hello_world
结果:工作,打印你好世界
5)右键clic on project - > configure - >转换为mavem项目
-
group id:test
-
artifact id:test
-
版本:0.0.1-SNAPSHOT
-
包装: jar
-
完成
6)运行scala应用程序
-
项目:测试
-
主类:test.hello_world
结果:
Error: Could not find or load main class test.hello_world
版本详情:
Eclipse 4.4.1 M2E 1.5.0 Scala IDE for Eclipse 4.0.0.nightly-2_11
生成的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
4 回答
不推荐使用http://scala-tools.org/repo-releases,这是一个有效的pom.xml:
要运行该应用程序:
运行 - > scala应用程序
项目:测试
主类:test.hello_world
你的pom.xml应该包含这些部分(更改课程的版本):
库:
插件存储库:
依赖关系:
Build :
去
跑
运行
Scala application
然后你无法在控制台中看到输出
可能是我的迟到回复但它可能有所帮助,下面的过程解决了我的问题 .
请检查源文件夹是否在构建路径上 . 如果源文件夹不在构建路径中,则无法在runas中看到作为scala应用程序运行
将源添加到构建路径1)右键单击项目属性2)在左侧窗格中选择Java Build Path,在source选项卡中单击add folder并选择源文件夹并单击ok