问题
I am wondering if some one could give me a demo. When I use less4j, in tag, what should I put in ? I searched online for a long time, but it seems that there are no information about using less4j in ANT at all.
But since less4j could be implemented in command line, so it must be implementable in ANT. Please help me with this, thanks!
回答1:
<?xml version="1.0" encoding="UTF-8"?>
<project name="compile" default="css.concatenate" basedir=".">
<property name="charset" value="utf-8"/>
<macrodef name="less4j">
<attribute name="src" />
<attribute name="css" />
<sequential>
<java dir="${basedir}/lib/com/github/sommeri/less4j/commandline" classname="CommandLine" fork="false">
<classpath>
<pathelement location="${basedir}/lib/less4j.jar" />
<pathelement location="${basedir}/lib/jcommander.jar" />
<pathelement location="${basedir}/lib/antlr-runtime.jar" />
<pathelement location="${basedir}/lib/commons-io.jar" />
<pathelement location="${basedir}/lib/commons-beanutils.jar" />
<pathelement location="${basedir}/lib/commons-logging.jar" />
</classpath>
<arg value="@{src}" />
<arg value="@{css}" />
</java>
</sequential>
</macrodef>
<!-- 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="css" depends="css.concatenate" description="Create CSS">
<mkdir dir="${basedir}/tryGotCSS" />
<less4j
src="${basedir}/src/main/webapp/cons/cons.less"
css="${basedir}/src/main/webapp/css/trycore.css" />
</target>
<target name="trasition" >
<echo> in trasition </echo>
</target>
<!-- precompile handlebars -->
<!-- -->
</project>
I was trying to run this script, but the build will fail for the reason that it could not find the class "Commandline"(which has the main method), but when I check the source code of less4j, I am pretty sure that the Commandline class is under the ${basedir}/lib/com/github/sommeri/less4j/commandline" classname="CommandLine.
来源:https://stackoverflow.com/questions/24684044/can-i-use-less4j-to-compile-less-into-css-in-ant