java Ant 构建在 Eclipse 中失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14744456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:14:35  来源:igfitidea点击:

Ant Build Failed in Eclipse

javaant

提问by Rithesh

I was building an jar file of my project using ANT after searching in Google found how do do it i referred thisink. Below is my build.xml file

在 Google 中搜索后,我正在使用 ANT 构建我的项目的 jar 文件,找到了我引用了这种墨水的方法。下面是我的 build.xml 文件

<?xml version="1.0" ?> 
<project name="ExcelData" default="compress">

    <target name="init">
        <mkdir dir="build/classes" />
        <mkdir dir="dist" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="src" destdir="build/classes" />
    </target>

    <target name="compress" depends="compile">
            <jar destfile="dist/ExcelData.jar" basedir="build/classes" />
    </target>

    <target name="execute" depends="compile">
        <java classname="com.spt.excel.data.ExcelData" classpath="build/classes" />
    </target>

    <target name="clean">
        <delete dir="build" />
        <delete dir="dist" />
    </target>

</project>

but the problem is the ANT building is failing. But i am getting errors as

但问题是 ANT 大楼正在失败。但我收到错误

D:\Eclipse\workspace\ExcelData\src\com\spt\excel\data\ExcelData.java:24: error: package org.slf4j does not exist`

And referred thislink to set tools.jar.

并参考链接设置tools.jar。

Can Anyone tell me where i am going wrong. Thank You in advance.

谁能告诉我我哪里出错了。先感谢您。

回答by Sergii Zagriichuk

you have no include libraries to your ant file, I mean classpath, just add all libs that your eclipse project contains to ant file and all will work, and please read original tutorial like this one

你的 ant 文件中没有包含库,我的意思是类路径,只需将你的 eclipse 项目包含的所有库添加到 ant 文件中,所有库都可以工作,请阅读像这样的原始教程

like that

像那样

<javac srcdir="${src.dir}" destdir="${classes.dir}">
    <classpath>
        <pathelement location="${lib.dir}/lib1.jar"/>
        <pathelement location="${lib.dir}/lib2.jar"/>
    </classpath>
</javac>

for libs

对于库

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

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="mylibs" debug="on"/>

add properties lib.dir

添加属性 lib.dir

 <property name="lib.dir"  location="{here is path to your libraries}"/>

回答by Nikolay Kuznetsov

For Eclipse I recommend following:

对于 Eclipse,我建议如下:

Right click your project -> Export -> Runnable Jar file 

Pick launch configuration, destination, extract required libraries into JAR, tick Save as ANT script

Finish.

Eventually you would have Jar file generated together with reusable Ant script.

最终,您将生成 Jar 文件和可重用的 Ant 脚本。

Then you analyze your Ant script.

然后分析您的 Ant 脚本。

Difference between extracting and packaging libraries into a jar file

将库解压和打包成jar文件的区别