user2759511
user2759511

Reputation: 640

Can scala-native use existing Java/Scala libraries?

I have not been able to understand if a project intended to be compiled by scala-native can:

  1. Use Java libraries? If yes, does it make scala-native an ahead of time compiler for Java as well as Scala?
  2. Use Scala libraries (compiled to JVM bytecode)

I understand only part of the Scala standard library is available. Is it because there are parts of the implementation using Java standard library?
In case it can't, wouldn't this drawback make it almost impossible for a [non-trivial] project to compile to both the JVM and native using a single code base? Are there plans in this direction?

Upvotes: 4

Views: 1698

Answers (3)

Andreas ZUERCHER
Andreas ZUERCHER

Reputation: 902

Conceivably JVM-executed Java libraries or Scala libraries could be invoked via JNI analogous to C/C++ invoking those libraries via JNI. The times to do so would be precisely when C/C++ would have needed to do so, which should be somewhere between rare (near zero) and anathema (vilely absolute zero).

Upvotes: 0

junkgui
junkgui

Reputation: 179

From scale-native.org it should support "fat" jar files, with classifies and NIR files--for example scalaz has added support for scala-native:

Publishing Scala Native supports sbt’s standard workflow for the package distribution:

Compile your code. Generate a jar with all of the classfiles and NIR files. Publish the jar to sonatype, bintray or any other 3rd party hosting service. Once the jar has been published, it can be resolved through sbt’s standard package resolution system.

Upvotes: 1

porl
porl

Reputation: 161

I'm far from an expert here but I asked a similar question on Reddit and received the answer that scala-native does not interact with Java libraries (so I took it that it could not compile them either).

It can connect to native ('c') libraries instead.

I don't know of any plans for this to change.

Upvotes: 4

Related Questions