aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Need to compress JS files using ant task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Need to compress JS files using ant task" Watch "Need to compress JS files using ant task" New topic
Author

Need to compress JS files using ant task

yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
Hi all

My working environment is:JSP,Struts 2.0,Ant based one build.xml,JS,HTML.

i want to compress my all js files as well remove all comments from that , so i need to one example of build.xml target , which help me to compress my all js files.

i had already goggling on it, i found the one jar based ant task example of htmlcompressor-1.5.3.jar.

it just compress my js files, not remove my comment portion from the js files.

i had try htmlcompressor-1.5.3.jar ant target with one simple js files only, Js file as below



when it compressed,that compressed file still contains this lines //alert('hy tested ok');,//document.getElmentByID('ping').value, in file,
what is meaning of this compression if it is not able to remove the comment portion from the js files,
and one more point i inform that i do not want to use this jar approach yuicompressor-2.4.6.jar.
i want any other solution which help me to compress the files , as well remove the comments from the js file also.
if anybody have other solution/approach/idea which help me to my issue.Then please share it with me.

Thanks & Regards
Yatin Baraiya
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Vatin,

for this problem you wont get specifc jar file but you need to write your own logic to replace the line from js file with Ant script.

You can use regex in ant script to remove the line which contains "//" ,try to make the script if you cant find the way let me know will send you the code ..

Regards
Jatan
yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
hi jatan bhavsar

first of thanks for the quick reply

here i have just given one types of comments only, it should be Single Line Comments,Multi-line Comments etc..
actually i don't want any types of comments in my compressed js files.So i can't going for the specific solution, is there any parameter option available for the my issue solution?Any option available in the htmlcompressor-1.5.3.jar. file use approach, one more time i say that i don't wan to use yuicompressor-2.4.6.jar approach.

if you can send me the code for the same, then please send me that code.

let me know if you wan to other information

Thanks & Regards
Yatin baraiya
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Yatin,

Sorry i am not aware of such jars but if you come across please let me know as i am also interested to know any jar file or well prepared solution for this.

Regards
Jatan
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2409
    
  28

What you need is a "minifier". Google for it. There are several minifiers out there now. I think a really popular one is YUI minifier. YUI minifier provides a Java API. Some people have built ant tasks and maven plugins using the YUI minifier.
 
jQuery in Action, 2nd edition
 
subject: Need to compress JS files using ant task