【问题标题】:How can i find Joda-Time Jar file on my Mac?如何在我的 Mac 上找到 Joda-Time Jar 文件?
【发布时间】:2022-01-15 12:40:36
【问题描述】:

据我所知,一旦您在 pom.xml 中使用了 maven 库,就会将一个 jar 文件下载到您的计算机上。 我在 pom.xml 中使用了 Joda-Time,但在我的 Mac 上找不到 joda-time-2.10.13.jar

【问题讨论】:

    标签: java macos pom.xml jodatime


    【解决方案1】:

    tl;博士

    查看由 Maven 维护的 .m2 文件夹,其中保存了其下载。

    乔达时间

    如果使用Apache Maven 作为您的依赖管理器,请访问Joda-Time 网站以查找您的POM 文件所需的条目。

    目前:

    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.10.13</version>
    </dependency>
    

    这是一个通过使用 Apache Maven Quickstart 原型启动新项目创建的示例 POM。我将其修改为 (a) 添加 Joda-Time 依赖项,(b) 对所有部分使用最新版本,以及 (c) 通过 &lt;maven.compiler.release&gt; 元素指定 Java 版本。

    <?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>
    

    保存您编辑的 POM,让 Maven 重新解析该 POM,然后清理并构建您的项目。过了一会儿(当下载发生时),去检查保存外部库的文件夹。验证文件夹是否包含joda-time-2.10.13.jar

    就我而言,在运行 macOS Big Sur 的 MacBook Pro 上,可以在以下位置找到 JAR:

    /Users/basil_dot_work/.m2/repository/joda-time/joda-time/2.10.13/joda-time-2.10.13.jar

    此时,编辑 .java 主文件以使用 Joda-Time 类。

    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() 
            );
        }
    }
    

    运行时,查看输出如:

    按音调时间为:2021-12-10T16:58:38.076-08:00

    java.time

    请注意,Joda-Time 项目现在位于 maintenance mode

    Joda-Time 的创建者 Stephen Colebourne 吸取了教训,继续领导JSR 310 项目。该项目导致 java.time 类被内置到 Java 8 及更高版本中。

    如果开始一个新项目,您应该使用 java.time 类而不是 Joda-Time。

    如果维护一个已经使用 Joda-Time 的应用,您可以继续使用 Joda-Time。该项目通过对tz database 的更新以及任何重要的错误修复进行维护。但由于没有进一步的功能工作,请考虑在方便时计划迁移到 java.time

    【讨论】:

    • 非常感谢!我找到了!
    【解决方案2】:

    据我所知,它只是将库的代码添加到导出的项目中,而不是直接将其下载到任何路径。如果你只是想要这个文件,你可以下载它here

    【讨论】:

      猜你喜欢
      • 2013-07-19
      • 2013-07-11
      • 2015-02-26
      • 2017-07-04
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 2013-02-02
      • 1970-01-01
      相关资源
      最近更新 更多