Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 100124

VS Code knows Scala and Java, but can't connect them

$
0
0

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:

  1. The import me.parent.jModule.WithinModule cannot be resolved : AccessScala[3,8]
  2. WithinModule cannot be resolved to a type : AccessScala [7,9]
  3. 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 ;)


Viewing all articles
Browse latest Browse all 100124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>