Getting illegal character error while using closure-compiler.jar using ANT for r.js optimization

375 views Asked by At

I am using closure compiler jar for minification in r.js optimization in windows environment.

While running this task using ANT exec, getting illegal character error but while running same task using .bat file it working fine.

ANT exec task

<target name="do-optimization" description="It will do optimization using r.js.">
    <exec dir="." executable="java" failonerror="true">
        <arg value="-jar" />
        <arg path="${src.dir}/r-js/lib/rhino/js.jar" />
        <arg path="${src.dir}/r-js/lib/closure/compiler.jar" />
        <arg path="${src.dir}/r-js/dist/r.js" />
        <arg value="-o"/>
        <arg path="${src.dir}/r-js/build.js" />
    </exec>
</target>

console output

do-optimization:
 [exec] js: "C:\workspace\test\ui\r-js\lib\closure\compiler.jar", line 2: illegal character
 [exec] js:   ╝MOC                   ♦ META-INF/■╩  PK♥♦
 [exec] js: ^
 [exec] js: "C:\workspace\test\ui\r-js\lib\closure\compiler.jar", line 1: Compilation produced 1 syntax errors.
 [exec]

 BUILD FAILED

optimize.bat

java -classpath "r-js\lib\rhino\js.jar";"r-js\lib\closure\compiler.jar" org.mozilla.javascript.tools.shell.Main r-js/dist/r.js -o build.js
1

There are 1 answers

0
M A On BEST ANSWER

It doesn't seem that the Ant script is calling java the same way as the batch file. The exec task is calling the following command:

java -jar ${src.dir}/r-js/lib/rhino/js.jar ${src.dir}/r-js/lib/closure/compiler.jar ${src.dir}/r-js/dist/r.js -o ${src.dir}/r-js/build.js

which is clearly different than the one in the .bat file, i.e. the jars are not being added to the classpath properly.

In Ant, you can simply use the java task to run a Java class. Try using the following:

<java classname="org.mozilla.javascript.tools.shell.Main" failonerror="true">
    <arg path="${src.dir}/r-js/dist/r.js" />
    <arg value="-o"/>
    <arg path="${src.dir}/r-js/build.js" />
    <classpath>
        <pathelement location="${src.dir}/r-js/lib/rhino/js.jar" />
        <pathelement location="${src.dir}/r-js/lib/closure/compiler.jar" />
    </classpath>
</java>