Using Joda Time in Scala (scalaj-time) with IntelliJ IDEA

EDIT:

Version information, starting from 01/27/2013:

Scala 2.10.0
IntelliJ IDEA Leda 123.139 (EAP)
Scala Plugin version 0.7.108 (nightly build)
Jdk 7u11
Joda time 2.1
ScalaJ-Time 2.9.1-0.6

I refused to work with SBT , because I did not see any progress in this - I am not sure how to combine IntelliJ and SBT , and after several hours of trying, I ended up where I first started.

My JodaTime library contains the Scalaj-Time flag: wAyuaTQ.png

I tried almost any combination of settings, from collaborative compilation (first Scala, then Java and vv), an external build, before I launched my JodaTime library through the Scala library in dependencies (yes, even made it) and invalid caches. All I get is a bunch of errors — it doesn't matter if I “make” a project, “Run” the current file, or “Compile” it - which are randomly generated. And sometimes it works. Yes, like an idiot, how that sounds, behavior that is undefined. I am not sure what the reason is. I counted 3 different error messages that will be displayed, I will upload them to pastie.org, otherwise it will take up too much space: http://pastie.org/pastes/5887847/text .

What I have not tried: Returning to earlier versions of any of the applications / libraries, see above, delving into SBT (I figured it wasn’t worth it).

What do I expect from this stream? I expect someone to provide a solid solution to this problem, which at best will not include the mention of SBT (optional).

Also, a side note : Why is Joda-Time sending its library in a broken format? Is there a secret that everyone should know about? What is the problem of including FromString in the release version? (I still think the reason for all this)

Yours faithfully,
Danyel

ORIGINAL MAIL: (you can ignore this)

I have the latest build of IntelliJ (123.139), Scala 2.10.0 and so far no problems have occurred.

Instead of using the Java time library, I really wanted to use Joda Time, and when I saw that there were tons of implications to use in Scala, I wanted to try this! I have added all the libraries, but the implications will not be recognized. When I tried to compile it through the IDEA popup menu, the following errors appeared:

 error while loading DateTime, class file '~\workspace\Libraries\JodaTime\joda-time-2.1.jar(org/joda/time/DateTime.class)' is broken (class java.lang.RuntimeException/bad constant pool tag 10 at byte 42) error while loading DateTimeZone, class file '~\workspace\Libraries\JodaTime\joda-time-2.1.jar(org/joda/time/DateTimeZone.class)' is broken (class java.lang.RuntimeException/bad constant pool tag 7 at byte 44) error while loading AbstractInstant, class file '~\workspace\Libraries\JodaTime\joda-time-2.1.jar(org/joda/time/base/AbstractInstant.class)' is broken (class java.lang.RuntimeException/bad constant pool tag 10 at byte 10) 

I went to the source of these DateTime and noticed that org.joda.convert.FromString; was imported, but the resource does not exist! I guessed that because of this, Scala would not compile. So I searched Google for what I should do. And everywhere he said "SBT, SBT !!", and I tried to find out what SBT is, so I installed it: Version 0.12.2, Manual installation (I use Windows 7) from http: //www.scala-sbt. org / . I wanted it to work with my IntelliJ, so I went to ~\.sbt\plugins and created a build.sbt file with the addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0") line addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0") and downloaded the zip from https://github.com/mpeltonen/sbt-idea , extracted it and went to the same folder with CMD, entering sbt and gen-idea into sbt, and he did a lot of things, and everything seemed to work . So I went to my project that I wanted to launch Joda Time, and, above all, it was very difficult to include Scala 2.10.0 in SBT. I created the file <PROJECT>\build.sbt and filled it with these lines:

 name := "Project" version := "1.0" scalaHome := Some(file("C:/Program Files (x86)/scala")) scalaVersion := "2.10.0" 

Then, to enable scalaj-time, I went to <PROJECT>\project\project\ and created build.sbt with the libraryDependencies += "org.scalaj" %% "scalaj-time" % "0.6" .

Finally, I went to <PROJECT> with CMD, entered "sbt", it (down) uploaded a lot of files, and it seemed to work, then I entered gen-idea , and everything was fine.

I opened IntelliJ and I could easily open a project. When I opened the project structure, I went to Modules, and there were two modules: Project and Project-build . I ignored Project-build alone, clicked on the Project module, and there were many source folders and test folders that were not there: src/main/scala , etc. I deleted them all and added src as the source folder.

I noticed that Joda-Time was not included in external libraries (by the way, I use Joda-Time 2.1 and Scalaj-time 0.6), so I had to add their myselves. The joda time library is .jar, and scalaj time is a folder, but that shouldn't be a problem, should it? I could run a simple println( DateTime.now ) statement (I don’t know if this was possible before, I didn’t try), but + 2.months still failed. Here is a screenshot for you to understand:

ZthyL.png

I think I explained in detail how I continued, and I hope you find something that I did wrong. I worked hard to solve this, but in the end I landed where I was in the beginning ...

Thank you for your time!

Hello!

+4
source share
2 answers

How to import FromString for joda-time?

It worked like a charm (for now, who knows how everything will happen). I'm so crazy that I did not think about it in the first place ... Grrrrr.

+4
source

EDIT:

This answer is not valid. See EDIT in the main post. As long as it works SOMETIMES, it is still very undefined as to WHEN it works. When I create a new project, it varies from work to non-working (not compiling, printing random errors), but in another larger project, it has the same undefined behavior, except for now (for some reason) it does not work, PERIOD. (In my new project, it is still changing)

ORIGINAL MAIL :

So, after another 10 minutes of trying and searching on Google, I found .JAR for Scalaj-time (0.6).

I thought: “Well, what harm can it do?”, Downloaded it and included it instead of a folder.

Tadaaaa, everything worked ... All I needed was just these lines:

 object Test extends App { import org.scala_tools.time.Imports._ println( DateTime.now + 2.months ) } 

No SBT, nothing, no other imports. You just downloaded scalaj_time from http://mvnrepository.com/artifact/org.scalaj/scalaj-time_2.9.1 (version 0.6, for now) and Joda Time (V 2.1), create a ScalajTime library that includes 2+ banks and add them to your addictions. All you need is one import statement and you are ready to go.

Perhaps the main problem was that I cannot import SOURCE files from libraries? Since the source folder I imported apparently had no effect. I do not know how I "ignored" this fact, but it was foolish to suppose.

So now it works.

Sincerely.

+2
source

All Articles