简体   繁体   English

将Scala添加到intellij中的现有Java模块

[英]Adding scala to existing java module in intellij

I have a maven project with multiple java modules and I am trying to add scala to one of them. 我有一个带有多个Java模块的Maven项目,我正在尝试将scala添加到其中一个。 If I create a separate scala module, it works, but if I try to add scala to one of the java modules it doesn't work. 如果我创建一个单独的scala模块,它可以工作,但是如果我尝试将scala添加到其中一个Java模块中,它将无法工作。

What I did: 我做了什么:

I added Framework Support for Scala to one of the modules like it says here . 在这里说的其中一个模块中添加了对Scala的框架支持。 Then scala disappeared from that list. 然后scala从该列表中消失了。

I created a new folder named "scala" under main and a helloworld.scala file. 我在main和helloworld.scala文件下创建了一个名为“ scala”的新文件夹。 I noticed that the scala folder is not blue like the java one, it's plain orange. 我注意到scala文件夹不是像Java文件夹那样的蓝色,而是纯橙色的。

When I try to run the helloworld object, I get: 当我尝试运行helloworld对象时,我得到:

Exception in thread "main" java.lang.ClassNotFoundException: helloworld
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:260)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)

I don't have any exprience with intellij or maven (in case it matters). 我对intellij或maven没有任何经验(以防万一)。 Been using eclipse all my life. 一生都在使用eclipse。

Using intellij 14 with scala 2.11 在scala 2.11中使用intellij 14

Somehow by mistake, I've managed to solve it. 不知何故,我设法解决了这个问题。 All I had to do was right click on my scala directory and Mark Directory as Sources Root 我要做的就是右键单击我的scala目录,然后将目录标记为Sources Root

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

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