I wanted to know if it is possible to use java.time package in java 8 in my scala 2.11 program?
then how to add it to my sbt project?
I wanted to know if it is possible to use java.time package in java 8 in my scala 2.11 program?
then how to add it to my sbt project?
You don't need to add anything to your project. java.time
is a standard part of Java, not an external third-party dependency.
You just need to make sure that your customers run your code on Java 8.
This has nothing to do with SBT. SBT is a Build Tool. It is about how you compile your code. But your problem is that you need to control how your customers run your code. You could do that simply by stating in your documentation that your code only works with Java 8+ and hope that your customers actually read that documentation. You could use a launcher that checks the Java version before running the main code and prints out a suitable error message.
java.time
is a part of Java. It has nothing whatsoever to do with Scala. It even has "Java" in its name! Your Scala version is completely and utterly irrelevant. If you have Java 8, you have java.time
. If you don't have Java 8, you can't use it. It doesn't matter if you are using Scala 2.11.5, Scala 2.11.8, Scala 2.12, Scala 1.0, Clojure, Groovy, Kotlin, Ceylon, Fantom, Ruby, Python, JavaScript, PHP, Scheme, CommonLisp, Java, or any other language.
Commented
Sep 5, 2016 at 23:33
Until Scala 2.12 comes along, Java 6, 7, or 8 can be used with any of its inbuilt packages and
java.time
is an inbuilt package.So can be used. However newest release Scala 2.12, will support Java 8 only.So any case yes it can be used in Java 8.
If you explicitly want this package in Scala you have to add Java.time dependency to sbt file.On maven central its replaced by Joda-time.Its an individual Java.time Api provided by Apache.
It can be found at https://mvnrepository.com/artifact/joda-time/joda-time
To use it add:
( libraryDependencies += Seq( "joda-time" % "joda-time" % "2.3" , "org.joda" % "joda-convert" % "1.6" // other dependencies )
to you sbt file.
joda-convert is needed for Scala compilation of Joda-time.It actually converts objects to and from Strings.
NOTE:If you explicity want to use java.time Scala implementation find Scal-Java-time link on Github.