java - Ant 无法检测到外部库?

标签 java ant build jar

我正在尝试关注this Ant guide ,并且我在尝试添加 log4j 外部库的部分中遇到错误。按照指南的说明,我已经下载了相应的this log4j jar并将其放入我的 lib 库中。我还尝试将 jar 文件直接解压到 lib 文件夹中。

错误是,虽然我已经导入了必要的库并将Ant指向了我的build.xml中,但它无法找到它。

error: package org.apache.log4j does not exist ...
error: could not find symbol BasicConfigurator.configure(); ...
                             ^

这是我的 build.xml 文件,它几乎是从示例中复制并粘贴的(减去“oata”包名称:

<property name="src.dir"     value="src"/>
<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>
<property name="main-class"  value="HelloWorld"/>
<property name="lib.dir"     value="lib"/>

<target name="clean">
    <delete dir="${build.dir}"/>
</target>

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

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

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" classpathref="classpath">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
        </manifest>
    </jar>
</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>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

最佳答案

I also tried just unpacking the jar file directly into the lib folder.

解压 JAR 是完全错误的。 永远不要这样做

您的链接引用的文件是 ZIP 文件,而不是 JAR。它里面有log4j-1.2.16.jar。如果打开它,您将在 org.apache.log4j 包中看到 BasicConfigurator.class。

关于java - Ant 无法检测到外部库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8797830/

相关文章:

java - 写入文件的路径(包含文件的文件夹的路径)

java - 如何在TFS中构建java项目

build - 触发 hudson/cloudbees 从 Atlassian Jira 构建?

java - Android,引用其他库

ant - 替换字符串 DIR 位置时使用 replaceregexp 的问题

Angular:在构建期间向 Assets 中的文件添加哈希

java - 类已完全更改为带有错误的 XML 标记

Java 泛型 : creating collections of class objects extending Throwable

java - Android Studio 2.2.0.12 设计器自动在 View ID 之前添加 "@+id"前缀,这会导致此异常错误

java - 使用 jersey 在 JAX-RS 中设置 @RolesAllowed 的角色