这是我使用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:Usersdi_yuworkspacelessCompilerbuild.xml
css.concatenate:
[echo] cons is done!
lessc:
[echo] now in compression
[java] Compiling... C:Usersdi_yuworkspacelessCompilersrcmainwebappconscons.less
css.concatenate:
[echo] cons is done!
css.concatenate:
[echo] cons is done!
lessc:
[echo] now in compression
[java] Compiling... C:Usersdi_yuworkspacelessCompilersrcmainwebappconscons.less
rename:
[echo] renaming...
[rename] DEPRECATED - The rename task is deprecated. Use move instead.
[delete] Deleting: C:Usersdi_yuworkspacelessCompilersrcmainwebappcsscons.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的run作为ANT来运行这个build.xml。
从文件中删除不需要的目标后是否更改了要运行的目标?在我看来,运行配置仍然在使用旧的目标。使用
问题是您创建了一个目标"预编译模板",随后将其删除…而Eclipse正在"记住"现在已经过时的目标。
建议:1)"文件>保存全部",2)"项目>清洁项目"Run As, Ant build"
看看这是否有效!
实际上,我发现了问题所在。我仍然使用旧的配置来运行build.xml。解决方案如下:
- 右键单击build.xml
- 点击"运行为…"然后点击外部配置工具
- 删除选中的启动配置。
Para - que le interesebuil.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";