使用Ant时出现奇怪的错误

时间:2014-07-18 13:24:29

标签: java xml eclipse ant

这是我使用ant。

的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="compile" default="css.concatenate" basedir=".">
<property name="charset" value="utf-8"/>

<!-- compile LESS -->

<target name="css.concatenate">
    <concat destfile="${basedir}/src/main/webapp/cons/cons.less">
        <fileset dir="${basedir}/src/main/webapp/less">
            <include name="*.less"/>
        </fileset>
    </concat>
    <echo>cons is done!</echo>
</target>

<target name="lessc" depends="css.concatenate">
    <echo>now in compression</echo>
    <java classname="CpLess" fork="true">
        <arg value="${basedir}/src/main/webapp/cons"/><!-- input folder that contains less file -->
        <arg value="${basedir}/src/main/webapp/css"/><!-- output folder -->
        <classpath>
            <pathelement location="${basedir}/lib/commons-logging.jar"/>
            <pathelement location="${basedir}/lib/js.jar"/>
            <pathelement location="${basedir}/lib/lesscss-engine.jar"/>
            <pathelement location="${basedir}/lib/yuicompressor.jar"/>
            <pathelement location="${basedir}/lib/zkjszips.jar"/>
            <pathelement location="${basedir}/lib/zkless.jar"/>
            <pathelement location="${basedir}/lib/zul.jar"/> <!-- only needed if using _zkmixins.less -->
        </classpath>
    </java>
</target>

<target name="rename" depends="lessc">
    <echo>renaming...</echo>
    <rename src="${basedir}/src/main/webapp/css/cons.css.dsp" dest="${basedir}/src/main/webapp/css/core.css"/>
    <delete file="${basedir}/src/main/webapp/css/cons.css.dsp.src"/>
    <echo>rename done</echo>
</target>


<target name="trasition" >
            <echo> in trasition </echo>

</target>



</project>

当我运行它时,会出现如下错误:

Buildfile: C:\Users\di_yu\workspace\lessCompiler\build.xml
css.concatenate:
 [echo] cons is done!
lessc:
 [echo] now in compression
 [java] Compiling...      C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\cons\cons.less
css.concatenate:
 [echo] cons is done!
css.concatenate:
 [echo] cons is done!
lessc:
 [echo] now in compression
 [java] Compiling...    C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\cons\cons.less
 rename:
 [echo] renaming...
 [rename] DEPRECATED - The rename task is deprecated.  Use move instead.
 [delete] Deleting:  C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\css\cons.css.dsp.src
 [echo] rename done
 trasition:
 [echo]  in trasition 

BUILD FAILED
Target "precompile-templates" does not exist in the project "compile". 

Total time: 4 seconds

如您所见,它表示“预编译模板”目标不存在。但是,我根本没有打电话给这个任务。我只是从我的build.xml中删除它,并没有其他与之相关的目标。错误是怎么来的? PS:我使用eclipse作为ANT来运行这个build.xml。

4 个答案:

答案 0 :(得分:0)

从文件中删除不必要的目标后,是否更改了要运行的目标?在我看来,运行配置仍在使用旧目标。使用

答案 1 :(得分:0)

问题是你创建了一个目标“precompile-templates”,你随后将其删除了......而Eclipse正在“记住”现在过时的目标。

建议: 1)“文件&gt;全部保存”,2)“项目&gt;清理项目”3)“运行方式,Ant构建”

看看是否有效!

答案 2 :(得分:0)

实际上,我发现了问题所在。我仍然使用旧配置来运行build.xml。解决方案是这样的:

  1. 右键单击build.xml
  2. 点击&#39;运行为...&#39;然后单击外部配置工具
  3. 删除所选的启动配置。

答案 3 :(得分:-1)

Para aquel que le interese 的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="less.compile" default="css.concatenate" basedir=".">
<!-- compile LESS -->
<target name="css.concatenate">
    <concat destfile="${basedir}/WebContent/cons/index.less">
        <fileset dir="${basedir}/WebContent/less/import">
            <include name="*.less"/>
        </fileset>
    </concat>
    <echo>cons is done!</echo>
</target>

 <target name="css.lessc">
        <java classname="CpLess" fork="true">
            <arg value="${basedir}/WebContent/cons"/><!-- output folder -->
            <arg value="${basedir}/WebContent/less"/><!-- output folder -->
            <classpath>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/commons-     logging.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/js.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/lesscss-engine-1.3.3.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/yuicompressor-2.4.7.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/zkjszips.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/zkless.jar"/>
                <pathelement location="${basedir}/WebContent/WEB-INF/lib/zul.jar"/><!-- only needed if using _zkmixins.less -->
            </classpath>
        </java>
    </target>

<target name="lessc">
    <java classname="CpLess" fork="true">
        <arg value="C:/WKSLuna000/PruebasZul/WebContent/lesssrc"/><!-- output folder -->
        <arg value="C:/WKSLuna000/PruebasZul/WebContent/lessbuild"/><!-- output folder -->
        <classpath>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/commons-logging.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/js.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/lesscss-engine-1.3.3.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/yuicompressor-2.4.7.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/zkjszips.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/zkless.jar"/>
            <pathelement location="${basedir}/WebContent/WEB-INF/lib/zul.jar"/><!-- only needed if using _zkmixins.less -->
        </classpath>
    </java>
</target>
</project>


En la carpeta cons/
                  /zk/
                      _header.less
                      _zkminis.less
                      _skvariables.less
En la carpeta less/
                  /import/
                         0index.less
                         button.less
                         ....
                         /zk/
                             _header.less
                            _zkminis.less
                            _skvariables.less

Archivo 0index.less:
@import "../bootstrap/less/variables.less";
@import "../bootstrap/less/mixins.less";
@import "zk/_header.less";