Using Assetic in Symfony2 on Windows box
Lets begin. My first post to the blog and first small note on Symfony2 development.
Recently I studied excellent Symblog tutorial for getting started in Symfony 2 development. I do all my development on Windows box. In part 5 of the tutorial we are going to use Assetic library to manage our assets, especially to compress CSS using YUI compressor. YUI compressor is written in Java. To make it work we need to download .jar file, put it somewhere and configure Symfony to use it at app/config/config.yml like this:
assetic: filters: yui_css: jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
Now if you try to do something from command line, like clearing cache php app/console cache:clear --env=prod or publishig assets php app/console --env=prod assetic:dump - you would get an error:
[RuntimeException]
The system cannot find the path specified.
I've discovered that it means that system cannot find our java.exe to execute YUI compressor. Digging through the Assetic library code I found that it searches for java executable under /usr/bin/java by default. To change it you need to add extra parameter to your config.yml:
assetic: ... java: x:/Progra~1/Java/jre6/bin/java.exe ...
I had to use short alias for long directory name because it has space and that was a problem.
Voila, YUI compressor started to work and generated compressed CSS for us.