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.2
- Released: 22 September 2013
- 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.2
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.
- Update lesscss-compiler dependency to 1.1.2, which in turns uses LessCSS 1.4.2.
- Update post-processing-filter dependency to 1.1.1
- Extract the processor/compiler part and put into its own project.
- Change package and Maven group to
nz.net.ultraq.lesscss
(dropped the 'web' part).
- Project structure reorganization after changes to the Gradle build scripts.
- Update post-processing-filter dependency to 1.0.2
- Minor fixes from the updated maven-support Gradle script.
- Switched from Ant to Gradle as a build tool.
- Made project available from Maven Central. Maven co-ordinates added to the Installation section.
- Initial release