A LessCSS filter/compiler for Java web applications. (Blog post on the 'origins' of this little project: Ultraq's Final MooCow » Blog » If only I'd waited.)
This filter will process any requests for URLs ending with .less, processing
the LESS file pointed to by the URL and converting it to a standard CSS file.
Once the file is processed, the result is cached to save on having to process it
again. Any changes to the LESS file will be picked up and cause the file to be
processed the next time it is requested.
- Current version: 1.1.3
- Released: ?? ??? 2014
- Java 7
- A Servlet 3.0 compliant servlet container
Copy the JAR from the latest release bundle,
placing it in the WEB-INF/lib directory of your web application, or build the
project from the source code here on GitHub.
Add a dependency to your project with the following co-ordinates:
- GroupId:
nz.net.ultraq.lesscss - ArtifactId:
lesscss-filter - Version:
1.1.3
Start writing LESS! Also, don't change <link rel="stylesheet" .../>
to <link rel="stylesheet/less" .../> like the LESS website advises. That
change only applies to using LESS on the client.
If you're not taking advantage of servlet 3.0 annotations, then you'll need to
specify the filter in your web.xml file, ideally as the last filter in the
processing chain so that a proper CSS file can be generated as soon as possible:
<filter>
<filter-name>LessCSSFilter</filter-name>
<filter-class>nz.net.ultraq.lesscss.LessCSSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LessCSSFilter</filter-name>
<url-pattern>*.less</url-pattern>
</filter-mapping>
<mime-mapping>
<extension>less</extension>
<mime-type>text/css</mime-type>
</mime-mapping>The mime-mapping element is optional, but helps some web development tools (eg:
FireBug) identify your .less files as CSS.
This filter only works on URLs which locate a file on the file system. This is a limitation of the way I've chosen to detect changes to the underlying file, which I've done using Java 7's NIO 2 package.