我有一个项目:实例化斯卡拉类从Java的时候都是在同一个项目
- 的src/main/JAVA/pkg2的/ JHelloWorld.java
- 的src/main /斯卡拉/的pkg1/HelloWorld的。斯卡拉
比方说HelloWorld.scala像:
package pkg2
object HelloWorld extends App {
println("Hello, world!")
}
如何从JHelloWorld调用了HelloWorld:
package pkg1;
public class JHelloWorld {
public static void main(String[] args) {
//pkg2.HelloWorld.main(args);
}
}
编译器抱怨pkg2的不存在...
我需要把Scala代码在不同的模块(JAR文件),并从那里走?
感谢您的输入,但最终这tutorial真的帮助。
虽然我用的是maven-scala-plugin
我有两个问题:
- 我没有设置源目录斯卡拉
- 我并没有建立Scala代码第一
现在我的聚甲醛看起来像这样:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<!-- Run scala compiler in the process-resources phase, so that dependencies
on scala classes can be resolved later in the (Java) compile phase -->
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<!-- Run scala compiler in the process-test-resources phase, so that
dependencies on scala classes can be resolved later in the (Java) test-compile
phase -->
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
选中此问题[答案](http://stackoverflow.com/a/12284158/1361560)。我想这是同样的问题 – brunofitas
你可以发布你的maven POM吗? –
instatiation在哪里发生,在当前代码中没有'new'。 – pedrofurla