Compile LESS"

From Documentation
Line 56: Line 56:
<!-- only needed if using _zkmixins.less -->
<!-- only needed if using _zkmixins.less provided by ZK -->

Revision as of 01:30, 8 November 2013

Compile LESS to CSS

If your LESS files don't use any DSP functions, you can simply compile it follow LESS official site's instruction. Or if you prefer to compile LESS from java, you can use lesscss-engine developed by Asual DZZD.

Compile LESS to DSP

If you prefer to use DSP page, here we introduce how to compile LESS to DSP files by Ant and Maven.

Compile LESS by Ant

  • Follow the online document to install Apache Ant.
  • Download the following necessary jars in your project/lib folder from zk repository (right click -> save as).
    • commons-logging.jar
    • js.jar
    • lesscss-engine.jar
    • yuicompressor.jar
    • zkjszips.jar
    • zkless.jar (extension from lesscss-engine)
    • zul.jar (extract file from sourceforge)
  • Write ant script build.xml file as the following sample under project folder, and change input folder and output folder as needed.
<?xml version="1.0"?>
<project name="less.compile" default="lessc" basedir=".">
    <target name="lessc">
        <java classname="CpLess" fork="true">
            <arg value="${basedir}/src/main/webapp/less"/><!-- input folder that contains less file -->
            <arg value="${basedir}/src/main/webapp/less"/><!-- output folder -->
                <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 -->
  • Execute ant command in command line tool.

Compile LESS by Maven

  • Modify pom.xml in maven project
<!-- Add Plugin Repository -->
		<name>ZK Maven Plugin Repository</name>
	<!-- only needed if using _zkmixins.less provided by ZK -->
		<!-- Add zkless-engine-maven-plugin -->
						<!-- LESS source folder -->
						<!-- *.CSS.DSP output folder -->
  • Execute mvn install command to trigger LESS compilation.

Compile LESS to DSP during Development phase

It is not friendly to debug LESS during development by running Ant. Therefore, we provide a servlet named ZKLessServlet that can be used in web project to develop LESS by simply refresh browser page.

Note: It is only recommended in development environment.

Steps to use ZKLessServlet within Maven Project:

  • Add maven dependency if you are using maven.
        <id>ZK CE</id>
        <name>ZK CE Repository</name>
    <!-- omitted other repository -->
    <!-- omitted other dependency -->
  • Add servlet settings in web.xml
    <!-- omitted other servlets -->
            <param-value>/less</param-value><!-- specify to the folder that contains *.less -->
            <param-value>.css.dsp</param-value><!-- specify output file suffix, default .css.dsp -->
            <param-value>true</param-value><!-- compress output, default true -->
        <url-pattern>/less/*</url-pattern><!-- specify to folder that contains *.less -->
  • Project structure and use LESS directly in zul page.
The project structure looks like as follows:
zkMavenWebProject - src/main/webapp
Use test.less inside test.zul as follows
<!-- test.zul -->
<?link rel="stylesheet" href="../less/test.less"?>
    <button label="test" />
  • Now you can modify LESS and see the result by refreshing browser page.

Version History

Last Update : 2013/11/08

Version Date Content

Last Update : 2013/11/08

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.