Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala import cannot be resolved in Java project #554

Open
s0meRandomDev opened this issue Jun 8, 2018 · 7 comments
Open

Scala import cannot be resolved in Java project #554

s0meRandomDev opened this issue Jun 8, 2018 · 7 comments
Labels

Comments

@s0meRandomDev
Copy link

s0meRandomDev commented Jun 8, 2018

I am working on a Java Play 2.6 project and wanted to switch from eclipse (ScalaIDE) to VSCode (because I use VSCode for everything else and I largely prefer to work with it rather than eclipse).

In Eclipse, I have no problem importing a Scala source ( scala.collection.Seq ) but in VScode, opening the same Eclipse project and having no problem with all other external librairies, it cannot resolve the scala.collection.Seq import. (more precisely it's the scala.collection import ).

When compiling my project in the console using sbt, I have no problem.
Also Eclipse is able to resolve that import. Maybe it has to do with the "Scala library container" exlipse plugins of ScalaIDE

Environment
  • Linux Ubuntu 16.04
  • JDK version: 1.8
  • Visual Studio Code version: 1.23.1
  • Java extension version: Language support for Java(TM) by Red Hat 0.26.0
Steps To Reproduce
  1. Create a Java play project using sbt
  2. Import it in ScalaIDE
  3. Create a class that imports scala.collection.Seq
  4. Open the project in VSCode.

Logs : No errors in the logs.

@s0meRandomDev
Copy link
Author

s0meRandomDev commented Jun 8, 2018

Ok so I solved my problem. It's not because of VS Code. For some reason the .classpath file is omitting two JARs that seem to be the "scala Library container" . When I manually add them the the .classpath file, it works.

I don't find this solution very clean though, so If anybody has a better suggestion, i'm all ears.

Lines added to the .classpath file :

<classpathentry kind="lib" path="/home/{username}/.eclipse/360744385_linux_gtk_x86_64/plugins/org.scala-lang.scala-library_2.12.3.v20170725-052526-VFINAL-6ac6da8.jar" sourcepath="/home/{username}/.eclipse/360744385_linux_gtk_x86_64/plugins/org.scala-lang.scala-library.source_2.12.3.v20170725-052526-VFINAL-6ac6da8.jar"/>
<classpathentry kind="lib" path="/home/{username}/.eclipse/360744385_linux_gtk_x86_64/plugins/org.scala-lang.scala-reflect_2.12.3.v20170725-052526-VFINAL-6ac6da8.jar" sourcepath="/home/{username}/.eclipse/360744385_linux_gtk_x86_64/plugins/org.scala-lang.scala-reflect.source_2.12.3.v20170725-052526-VFINAL-6ac6da8.jar"/>

@fbricon
Copy link
Collaborator

fbricon commented Jun 8, 2018

Sorry but vscode-java doesn't support scala:

  • As you guessed, Scala IDE adds this "Scala library container" which is not available in vscode-java (or rather, jdt.ls).
  • the scala files would not compile automatically without Scala IDE's Scala builder.
  • sbt's not supported at all.

I'm not a Scala user so I don't have the answers. Maybe switching to Maven would help (probably not), but right now, tweaking the .classpath is your best option

@JYInMyHeart
Copy link

<clas

I do so. But vscode still can't resolve scala imports.

@jdneo jdneo added the compile label Feb 13, 2023
@Sigma711
Copy link

Sigma711 commented Sep 2, 2024

So does it solve now?

@jonefeewang
Copy link

has the same issue
BTW: there is post on stack overflow: https://stackoverflow.com/questions/60189566/vs-code-knows-scala-and-java-but-cant-connect-them

@tambonbon
Copy link

Apparently using Metals extension works for project that has both java and scala.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants