Can I use less4j to compile less into css in ANT?

柔情痞子 提交于 2019-12-12 02:05:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!