【问题标题】:Ant / External librariesAnt / 外部库
【发布时间】:2016-10-14 17:48:58
【问题描述】:

当我使用外部库 (lucene) 并通过 eclipse (运行应用程序) 运行我的 java 应用程序时,所有的类路径中的库都可以正常工作。
但是当我使用 Ant 时,我在这里遇到了这个错误:

java.lang.ClassNotFoundException: org.apache.lucene.store.Directory

我猜这个错误出现了,原因是类路径不正确。当 ant 编译代码时,没有发生编译错误。这是我的 ant 文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build">
    <path id="classpath">
        <pathelement location="bin"/>
        <pathelement location="GUI_P/lucene-6.2.0/lucene-6.2.0/analysis/common/lucene-analyzers-common-6.2.0.jar"/>
        <pathelement location="GUI_P/lucene-6.2.0/lucene-6.2.0/core/lucene-core-6.2.0.jar"/>
        <pathelement location="GUI_P/lucene-6.2.0/lucene-6.2.0/grouping/lucene-grouping-6.2.0.jar"/>
        <pathelement location="GUI_P/lucene-6.2.0/lucene-6.2.0/queryparser/lucene-queryparser-6.2.0.jar"/>
        <pathelement location="GUI_P/lucene-6.2.0/lucene-6.2.0/queries/lucene-queries-6.2.0.jar"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target depends="init" name="build">
        <javac debug="true" destdir="bin" includeantruntime="true">
            <src path="src"/>
            <classpath refid="classpath"/>
        </javac>
    </target>    
    <target name="jar" depends="build">
        <mkdir dir="GUI_P"/>
        <jar destfile="GUI_P/GUI_P.jar" basedir="bin">
            <manifest>
                <attribute name="Main-Class" value="gui.Gui"/>
            </manifest>
        </jar>
    </target>
    <target name="copySamples" depends="jar">  
        <copy todir="GUI_P/samples">
          <fileset dir="src/gui/samples"/>
         </copy>
    </target>   
</project>

你能帮帮我吗?

【问题讨论】:

  • GUI_P 是什么?在任何平台上似乎都不是有效路径。

标签: java eclipse ant


【解决方案1】:

这并不奇怪,因为ClassNotFoundException 总是在尝试动态实例化 时出现(通过Class.forName())。因此,相同的类路径可能会产生正确的编译,但对于执行来说并不完整:它缺少动态依赖项

在您的情况下,您必须将 lucene-core 库添加到执行类路径(至少)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多