23

I've had trouble getting Joda Time to install and work.

Most of the instructions around assume a certain amount of knowledge.

Can someone please assume I know nothing and guide me through, step by step, where to put the Joda Time zip file, do I extract it? How to add it properly using eclipse and how to import it into a class file.

Thanks very much! :)

Rich
  • 231
  • 1
  • 2
  • 3

4 Answers4

36
  1. Create your java project in eclipse
  2. Download the latest JodaTime .tar.gz file, and extract its contents
  3. In Eclipse look for your project at package explorer and right click on it then call it New -> Folder -> libs
  4. Copy/Drag joda-time-2.1.jar into the new created libs folder
  5. Right click on your project again (in package explorer) then Properties -> Java Build Path -> Libraries -> Add Jars -> joda-time-2.1.jar
  6. Now you can test with this code :

    DateTime test = new DateTime();

if code compiled ok you are good to go

CJBS
  • 15,147
  • 6
  • 86
  • 135
idanakav
  • 1,466
  • 1
  • 13
  • 23
  • I did 1, 2 and 3, my unzipped tar.gz is a .tar, not a .jar – Dimitri Kopriwa May 07 '15 at 12:53
  • Thanks @idaNakav. Followed your instructions in **Android Studio**. Extracting `tar.gz` yielded another `.tar`. [This resource](http://answers.informer.com/14050/how-to-convert-a-tar-file-to-a-jar-format) mentioned it cannot be converted to a `.jar`, but that a simple rename _might_ work. I renamed it, right clicked on it in the `libs` folder and picked `Add as Library`. Gradle did its work and imported it properly. – Narayana J Jul 12 '16 at 00:49
4
  • Download the zip file
  • Unzip it in a directory of choice
  • Make sure the joda-time-2.1.jar file is in your classpath when you compile and run your program

The classpath is the set of directories and JAR files that Java tools such as the compiler (javac) and the launcher (java) use to find compiled *.class files. See Setting the class path if you don't know how to do that.

For Eclipse: Right-click your project, choose Properties. Select "Java Build Path". Click "Add External JARs...". Select the file joda-time-2.1.jar, click Open, OK.

Jesper
  • 202,709
  • 46
  • 318
  • 350
4

from the docs: http://joda-time.sourceforge.net/installation.html

"The download will contain the joda-time jar file. Once you add this to your classpath you will be able to use Joda-Time."

Which means:

  1. you have to extract the zip file you have downloaded.
  2. it is indifferent, where you put the contents of the zip
  3. you'll have to add the jar file (which were in the zip) to the classpath of the project. In Eclipse: right click on the Project/configure build path/add JAR

Once you have added the JAR to the classpath, you can use it in any class of your own. You'll just have to import the Joda class you are using. e.g.:

import org.joda.time.DateTime;

keep it up

bpgergo
  • 15,669
  • 5
  • 44
  • 68
1
  1. Unzip and copy the main jar file somewhere on your machine
  2. Follow these instructions to add the library (jar file) to your project in eclipse
  3. you can start using jodatime, by adding the relevant import statement at the beginning of your class file (or just type DateTime for example, then CTRL+SPACE and eclipse should add the import for you).
assylias
  • 321,522
  • 82
  • 660
  • 783