How to use ThreeTen in an Ant project?

I have some kind of legacy Java 6 project, and I want to bring them some updates, such as the Java 8 time library. I found that this is possible using backport. But I do not know how to use it with the Ant build tool. Any good links or examples please?

+4
source share
1 answer

Overview:

  • Upload the ThreeTen Backport JAR file to the lib folder of your Ant project
  • Make sure the JAR files in your lib folder are in the classpath for compilation and execution (this may be so).
  • In Java source files, add imports from org.threeten.bpwith subpackages and use the imported classes in your code.

Download JAR

http://www.threeten.org/threetenbp/ Release → Download, Maven. ( threetenbp 1.3.6 10 2017 ) "" jar. ( threetenbp-1.3.6.jar) lib Ant. JAR. , lib.

JAR, , build.xml. build.xml

<property name="lib.dir"     value="lib"/>

<path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

lib . , , .jar lib , JAR . , :

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>

<target name="run" depends="jar">
    <java fork="true" classname="${main-class}">
        <classpath>
            <path refid="classpath"/>
            <path location="${jar.dir}/${ant.project.name}.jar"/>
        </classpath>
    </java>
</target>

, JAR / , .

java.time Java

. , import org.threeten.bp.

package ovv.ant.threetenbp;

import java.util.Date;

import org.threeten.bp.Instant;
import org.threeten.bp.DateTimeUtils;

public class AntAndThreeTenBackportDemo {

    public static void main(String... commandLineArguments) {
        Instant once = Instant.parse("1939-11-19T16:30:00Z");
        Date oldfashionedDateObject = DateTimeUtils.toDate(once);
        System.out.println("As Date: " + oldfashionedDateObject);
    }

}

Ant ( /), :

run:
     [java] As Date: Sun Nov 19 17:30:00 CET 1939

Ant 1.9.7, , .

Ant , " " .

+2

Source: https://habr.com/ru/post/1693351/


All Articles