|
wro4jRunner
Details about wro4j-runner command line utility.
Featured Read original blog post. Related pages: AvailableProcessors - a list of processors provided by wro4j and their alias. IntroductionStarting with wro4j-1.3.4 release, it is not limited anymore to java development environment. If, for instance, you are developing a js framework with many small modules (ex: jquery, yui, mootools, etc) or if you are working on the client-side of a large web project, then wro4j can help you to easily organize all your static resources (css/js) and build them (merge and minimize) using a simple command line tool. The only prerequisite is to install jdk-1.6 on your machine. A typicall a client-side project uses ant build script (build.xml) to describe how the js resources are merged and minimized. Also the supported compressors is limited to one only. Switching to another compressor is not supported. Using an ant script can be a good solution, but it also can be quite complex. Having a verbose and complex script is very hard to understand and maintain. Isn't there a simpler solution? Since version (1.3.8) of wro4j-runner allows you to validate your javascript resources (using jsHint) and css resources (using cssLint). Since version 1.4.2 the jsLint support is available. Installation StepsWith new wro4j command line tool, you can achieve the same results with minimum effort. All you have to do, is to follow the following steps: Add wro4j-runner.In our case, we add it to the lib folder (just where other jar files resides). The default relative context path depends on the location of the jar (this can be changed with an argument we'll get back to this later). Create wro.xml file and add it in the same folder where the jar is located.This file describes how you want your resources to be merged and the resources location. For more details about wro.xml, visit this page. Here is an example: <groups xmlns="http://www.isdc.ro/wro">
<group name="all">
<js>/jquery-1.4.2.js</js>
<js>/../src/**.js</js>
</group>
</groups>Run the following in your consolejava -jar wro4j-runner-1.4.5-jar-with-dependencies.jar As a result, a new folder (called 'wro') will be created. It will have one file: all.js containing a merged content of all js files from ui folder (as described in wro.xml). ConfigurationOf course, it would be nice to have the all.js file compressed. In order to do that, make a small change to the console script: java -jar wro4j-runner-1.4.5-jar-with-dependencies.jar -m Adding -m attribute, inform the wro4j runner to minimize the scripts. By default, it uses JSMin processor for js compression. You can easily switch this compressor with other, here is an example: java -jar wro4j-runner-1.4.5-jar-with-dependencies.jar -m -c uglifyJs This will inform wro4j runner to use UglifyJs compressor instead. Similarly, you can use other compressor. You don't have to worry when invoking the wro4j-runner with wrong arguments, it will inform you about the cause of the problem and in some cases can suggest possible solutions. Also, when everything is ok, you will see in command line the details about processing and total duration of the operation. Supported ProcessorsCurrently wro4j-runner support the following js compressors:
Processors available since 1.3.8 version
For a complete list of supported processors see this page: AvailableProcessors You can easily switch between any of the preferred compressors, depending on your tastes or preferences. Maybe for some projects one compressor suites better than other. The nice part is that wro4j can support any possible existing javascript compressors. For more details visit wro4j project home page. wro4j-runner argumentsHere you'll find all the arguments supported by wro4j runner tool.
ExamplesRunning lessCss with wro4j-runnerjava -jar wro4j-runner-1.4.5-jar-with-dependencies.jar --preProcessors lessCss Running cssLint with wro4j-runnerjava -jar wro4j-runner-1.4.5-jar-with-dependencies.jar -m -c cssLint Running jsHint with wro4j-runnerjava -jar wro4j-runner-1.4.5-jar-with-dependencies.jar -m -c jsHint Use several pre processorsjava -jar wro4j-runner-1.4.5-jar-with-dependencies.jar -m --preProcessors cssLint,yuiJsMin,cssMin | |
Not sure how to specify used processors. Could you explain it, please?
I've updated the wiki page with an example (@see Use several pre processors section)
Is there a way to specify a Post Processors for merged files?
Not yet, but it is on the roadmap: http://code.google.com/p/wro4j/issues/detail?id=395