Is there a way, preferred standard way to import Scala code (local jar, or local maven, or remote artifactory)?
We are using Groovy on Grails, and some library we want to use are written in Java or Scala. Considering they are all JVM languages, there must be a way to interplay.
I've search the net, but have not get a clear answer.
Both Scala and Java compiles into Java Bytecode ( .class
files) and packed as .jar
files. It's same bytecode, and can be used from any other JVM language under same classpath.
So your app can mix java bytecode produces from any other JVM language, including Java, Groovy, Scala, Clojure, Kotlin, etc. You can put such jars into /lib
dir (if your Grails version supports this; it's less preferred way) or as dependency from Maven repository (local or remote). Then you can use such classes from your code
See:
PS there could be some incompatibilities with some classes, because of different nature of sources languages. But in general it should work.
Did some simple tests. In hello-world example, just use
groovy -cp the-assembly-SNAPSHOT.jar main-file.groovy
And in the main-file.groovy
, should have an import
, like in Java/Scala
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.