Compile LESS

From Documentation

Install Node.js

Node.js is now required for our ZK-Less Engine since ZK 7.0.3.

If you don't have Node.js installed yet, please follow the steps given by the official-website to install Node.js.

Compile LESS to DSP

Here we introduce two ways to compile LESS files to DSP files. One is by Ant and the other is by Maven.

You could choose either one of them depends on your preferences.

Compile LESS by Ant

  • Have Node.js installed in your environment.
  • Follow the online document to install Apache Ant.
  • Download the following necessary jars into your project/lib folder from zk repository (right click -> save as).
    • yuicompressor.jar
    • zkjszips.jar
    • commons-io.jar
    • CssCompressor.jar
    • zul.jar (extract file from sourceforge)
  • Execute the following command under your project folder to install ZK-Less' node package.
cd project_folder
npm install zkless-engine
  • Write an ant script build.xml file like the following sample under project folder, and change the input folder and output folder as needed.
<?xml version="1.0"?>
<project name="less.compile" default="lessc" basedir=".">
    <target name="lessc">
        <exec executable="node">
            <!-- location of the engine's core file -->
            <arg value="${basedir}/node_modules/zkless-engine/lib/CpLess.js"/>
            <!-- input folder that contains less files-->
            <arg value="${basedir}/src/main/webapp"/>
            <!-- output folder -->
            <arg value="${basedir}/src/main/webapp"/>
            <!-- path of zul.jar -->
            <arg value="${basedir}/lib/zul.jar"/>
        <!-- compress the result using zk's Css Compressor -->
        <java classname="CompressCss" fork="true">
            <!-- input folder (same as above) -->
            <arg value="${basedir}/src/main/webapp"/>
            <!-- output folder (same as above) -->
            <arg value="${basedir}/src/main/webapp"/>
                <!-- required jars -->
                <pathelement location="${basedir}/lib/zkjszips.jar"/>
                <pathelement location="${basedir}/lib/yuicompressor.jar"/>
                <pathelement location="${basedir}/lib/commons-io.jar"/>
                <pathelement location="${basedir}/lib/CssCompressor.jar"/>
  • Execute ant command in command line tool, i.e:
cd project_folder
ant lessc

Compile LESS by Maven

  • Have Node.js installed in your environment.
  • Execute the following command to install the native LESS engine by Less.js
npm install -g less
  • 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 -->
                        <!-- Compress Option, default is true -->
                        <!--  <compress>false</compress> -->
  • 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 or Maven each time you modify your LESS files. Therefore, we provide a servlet named

ZKLessServlet that can be used in web project to develop LESS by simply refreshing the browser page.

Note: This is only recommended in development environment.

Steps to use ZKLessServlet within a Maven Project:

  • Have Node.js installed in your environment.
  • Install the native LESS engine by the following command:
npm install -g less
  • 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 -->
            <!-- specify to the folder that contains *.less -->
            <!-- specify output file suffix, default .css.dsp -->
            <!-- compress output, default true -->
        <!-- specify to folder that contains *.less -->
  • Project structure and use LESS directly in zul page.
Project structure should look like the following:
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 your browser page.

Version History

Last Update : 2014/09/11

Version Date Content

Last Update : 2014/09/11

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