As far as i know, once you use a maven library in pom.xml , a jar file will be downloaded to your computer. I have used Joda-Time in my pom.xml , but i cannot find the joda-time-2.10.13.jar on my Mac
CodePudding user response:
As far as I know, it only adds the library's code to the exported project but does not directly download it to any path. If you just want the file you can download it here
CodePudding user response:
Joda-Time
If using Apache Maven as your dependency manager, visit the Joda-Time web site to find the needed entry for your POM file.
Currently:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.13</version>
</dependency>
Here is an example POM created by starting a new project with the Apache Maven Quickstart archetype. I modified this to (a) add the Joda-Time dependency, (b) use latest versions for all parts, and (c) specify version of Java via <maven.compiler.release>
element.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>work.basil.example</groupId>
<artifactId>JodaTimeExample</artifactId>
<version>1.0-SNAPSHOT</version>
<name>JodaTimeExample</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.13</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Save your edited POM, make Maven re-parse that POM, and clean-and-build your project. After a while (while downloads happen), go check the folders where your external libraries are kept. Verify the folder contains joda-time-2.10.13.jar
.
In my case, on a MacBook Pro running macOS Big Sur, the JAR could be found at:
/Users/basil_dot_work/.m2/repository/joda-time/joda-time/2.10.13/joda-time-2.10.13.jar
At that point, edit the main .java
file to use the Joda-Time classes.
package work.basil.example;
import org.joda.time.DateTime;
/**
* Hello world!
*/
public class App
{
public static void main ( String[] args )
{
System.out.println(
"At the tone the time will be: "
DateTime.now()
);
}
}
When run, see output such as:
At the tone the time will be: 2021-12-10T16:58:38.076-08:00
java.time
Be aware that the Joda-Time project is now in maintenance mode.
The creator of Joda-Time, Stephen Colebourne, took lessons learned and went on to lead the JSR 310 project. That project resulted in the java.time classes being built into Java 8 and later.
If starting a new project, you should use the java.time classes rather than Joda-Time.
If maintaining an app that already uses Joda-Time, you may continue using Joda-Time. The project is maintained with updates to the tz database, and with any crucial bug fixes. But since no further feature work is being done, consider planning for a migration to java.time when convenient.