I am trying to interoperate Scala with Java, and have managed to create a Maven based project (repository here) that compiles fine from commandline (mvn clean package
).
However, I keep running into the issue that my IDE (VS Code) doesn't understand the interoperation at all.
The Problems
The file AccessScala.java
is trying to access a variable in WithinModule.scala
.
package me.parent.jModule;
import me.parent.jModule.WithinModule;
public class AccessScala {
public static void main(String[] args) {
WithinModule within = new WithinModule();
// -- this is like a static variable, but Scala doesn't allow that
// System.out.println(WithinModule.string());
// -- this is the auto-generated getter
System.out.println(within.string());
// -- this getter was manually added
System.out.println(within.getString());
}
}
VS Code raises three problems:
- The import
me.parent.jModule.WithinModule
cannot be resolved :AccessScala[3,8]
WithinModule
cannot be resolved to a type :AccessScala [7,9]
WithinModule
cannot be resolved to a type :AccessScala [7,35]
Project Setup
The project has two modules, but right now only jModule
is relevant. it contains Java and Scala code in separate folders. sModule
contains some Scala code that I wanted to access as well, but my current problem has nothing to do with Maven modules and everything with VS Code understanding the Scala-Java connections.
> parent
| > jModule
| | > src/main
| | | > java/me/parent/jModule
| | | | > AccessScala.java
| | | > scala/me/parent/jModule
| | | | > WithinModule.scala
| | > build.sbt
| | > project/build.properties
| | > pom.xml
| > sModule
| | > src/scala/me/parent/sModule
| | | >ExternalModule.scala
| | > pom.xml
| | > build.sbt
| | > project/build.properties
| > build.sbt
| > project/build.properties
| > pom.xml
VS Code
I'm using the Java Extention Pack, Scala-Metals and Scala Syntax
Both for Java and Scala it detects errors etc, so it knows Scala is there.
Question
Why does VS Code complain and what could I do to make this work? Is there a way at all, or do I just have to use IntelliJ (i have other problems there, stay tuned for those questions ;)
--add-opens
flags in command line. – Housework