问题
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! :)
回答1:
- Create your java project in eclipse
- Download the latest JodaTime
.tar.gz
file, and extract its contents - In Eclipse look for your project at package explorer and right click on it then call it
New -> Folder -> libs
- Copy/Drag joda-time-2.1.jar into the new created libs folder
- Right click on your project again (in package explorer) then
Properties -> Java Build Path -> Libraries -> Add Jars -> joda-time-2.1.jar
Now you can test with this code :
DateTime test = new DateTime();
if code compiled ok you are good to go
回答2:
- 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.
回答3:
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:
- you have to extract the zip file you have downloaded.
- it is indifferent, where you put the contents of the zip
- 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
回答4:
- Unzip and copy the main jar file somewhere on your machine
- Follow these instructions to add the library (jar file) to your project in eclipse
- you can start using jodatime, by adding the relevant
import
statement at the beginning of your class file (or just typeDateTime
for example, then CTRL+SPACE and eclipse should add the import for you).
来源:https://stackoverflow.com/questions/12105164/java-joda-time-download-and-install-step-by-step