Less CSS For Java
Java Shell
Failed to load latest commit information.
src Added additional javadoc, mainly around the function classes and the … Apr 13, 2011
.gitignore Added .gitignore file Apr 8, 2011
COPYRIGHT Updated LICENSE file to contain Apache License 2.0 Mar 17, 2011
LICENSE Updated LICENSE file to contain Apache License 2.0 Mar 17, 2011
README.md Renamed README to README.md and updated with markdown tags Apr 9, 2011
TODO Added support for @keyframes and @-webkit-keyframes CSS elements Apr 10, 2011
pom.xml [maven-release-plugin] prepare for next development iteration Apr 13, 2011


What is LessCSS4j?

LessCSS4j is a java implementation of the LESS language (http://lesscss.org). This version has all of the features of the original plus a few additional features:

  • Support for Internet Explorer CSS oddities without the need for escaping
  • Pluggable architecture to allow additional functions and transformations to be provided.
  • Optional Spring integration
  • Optional Servlet API integration


The original implementation of Less was written in Ruby. This turned out to to run much too slowly for our purposes when run using JRuby. To solve this problem, LessCSS4j was written.

While Less has since been reimplemented (less.js) in JavaScript and performs much better (Using NodeJS), there is still is a need for a Java version to ease the integration with existing web frameworks.


See LICENSE for more information

Command Line Usage

LESS files can be compiled on the command line using the following:

$ jlessc.sh myfile.less

This will produce the file myfile.css in the same directory as myfile.less.

An optional output filename may be provided. If the output filename is -, the output is written to standard out.

Use the --help or -h option for all of the options accepted.

Servlet Usage

LessCSS4j provides a servlet to perform runtime compilation of LESS files. To use it, add the following servlet to your web.xml file (shown with the default init parameter values):

        <!-- The amount of time to cache the compiled Less file
             -1 = cache forever -->
        <!-- The amount of time the browser should cache the resulting
             CSS file -->
        <!-- If set to 'true', the resulting CSS will be formatted. Otherwise
             the resulting CSS is minified -->


With this configuration, a request for the url /less/path/to/file.less will look for the file /path/to/file.less in the servlet context, compile it using the LessCSS4j compiler and return the resulting CSS. In addition, the result is optionally cached to avoid recompilation.

Embedded Compiler Usage

The easiest way to embed the LessCSS compiler is shown in the following code snippet:

StyleSheetResource resource = new FileStyleSheetResource(filename);
LessCssCompiler compiler = new DefaultLessCssCompilerFactory().create();
compiler.compile(resource, System.out, null);

Spring Integration

To embed the LessCSS compiler using the Spring Framework, several classes have been provided in the org.localmatters.lesscss4j.spring package:

  • LessCssCompilerFactoryBean

    FactoryBean implementation derived from DefaultLessCssCompilerFactory that allows the compiler to be configured via standard Spring XML wiring.

  • SpringStyleSheetResourceLoader

  • SpringStyleSheetResource

    Adapter classes that wrap Spring ResourceLoader and Resource implementations, respectively.