rajjaiswalsaumya / webutilities

Automatically exported from code.google.com/p/webutilities
0 stars 0 forks source link

Using yuiMinFilter JS files are not minified #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
   From today i started working on this filter. After implementing it the way mentioned in (http://code.google.com/p/webutilities/wiki/UsingWebUtilities), the CSS files are minified and working but none of the JS files are minified.
Even when I view source of the page and clicked on JS link, I found there was 
en error:

<html><head><title>Apache Tomcat/6.0.18 - Error report</title><style><!--H1 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-s
ize:22px;} H2 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-s
ize:16px;} H3 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-s
ize:14px;} BODY 
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P 
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px
;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> 
</head><body><h1>HTTP Status 500 - </h1><HR size="1" 
noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> 
<u></u></p><p><b>description</b> <u>The server encountered an internal error () 
that prevented it from fulfilling this request.</u></p><p><b>exception</b> 
<pre>javax.servlet.ServletException: Filter execution threw an exception
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:125)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:76)
    org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchFieldError: instance
    org.mozilla.javascript.CompilerEnvirons.&lt;init&gt;(CompilerEnvirons.java:48)
    com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:310)
    com.yahoo.platform.yui.compressor.JavaScriptCompressor.&lt;init&gt;(JavaScriptCompressor.java:533)
    com.googlecode.webutilities.yuimin.YUIMinFilter.doFilter(YUIMinFilter.java:184)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:125)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:76)
    org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)

</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available 
in the Apache Tomcat/6.0.18 logs.</u></p><HR size="1" 
noshade="noshade"><h3>Apache Tomcat/6.0.18</h3></body></html>

Can you please help.

Thanks,
Rahul

Original issue reported on code.google.com by rahulvat...@gmail.com on 18 Oct 2011 at 9:50

GoogleCodeExporter commented 8 years ago
Hi,

The root cause per log is this...
-----------------------------------
....
java.lang.NoSuchFieldError: instance
    org.mozilla.javascript.CompilerEnvirons.<init>(CompilerEnvirons.java:48)
....
-----------------------------------

And that points to I think mozilla "rhino". Can you please tell me what version 
of yuicompressor you are using?  Also can you share you Filter init params? 

Original comment by rr.patil...@gmail.com on 18 Oct 2011 at 11:01

GoogleCodeExporter commented 8 years ago
Hi MR Patil,
  Thanks for replying.
I am using yuicompressor-2.4.6.
The Filter init params are:
        <init-param>
            <param-name>lineBreak</param-name>
            <param-value>8000</param-value>
        </init-param>

I had tried removing the init params as well, as they are optional as per the 
documentation, but no luck.

Thanks,
Rahul

Original comment by rahulvat...@gmail.com on 18 Oct 2011 at 11:31

GoogleCodeExporter commented 8 years ago
By any chance do you have any "rhino.jar" in your classpath, lib?

Original comment by rr.patil...@gmail.com on 18 Oct 2011 at 11:55

GoogleCodeExporter commented 8 years ago
Can you share full stack trace for this issue from your tomcat log? You can 
attach the file here.

Original comment by rr.patil...@gmail.com on 18 Oct 2011 at 11:57

GoogleCodeExporter commented 8 years ago
No I don't have rhino.jar in my classpath, lib as it was not mentioned in 
documentation.
Should I put it there ?

Full stack trace I will be able to send you tomorrow morning first thing, as I 
work on remote desktop and right now I don't have its connectivity.

Original comment by rahulvat...@gmail.com on 18 Oct 2011 at 5:34

GoogleCodeExporter commented 8 years ago
Server log file attached.

Original comment by rahulvat...@gmail.com on 19 Oct 2011 at 3:42

Attachments:

GoogleCodeExporter commented 8 years ago
I have even tried putting rhino.jar (rhino-1.6R7.jar) in classpath/lib but 
still no luck. The error remains the same.

Thanks,
Rahul

Original comment by rahulvat...@gmail.com on 19 Oct 2011 at 4:16

GoogleCodeExporter commented 8 years ago
Thanks for the log. This is strange! If you look at source of 
CompilerEnvirons.java 
(http://www.java2s.com/Open-Source/Java-Document/Scripting/rhino-1.7/org/mozilla
/javascript/CompilerEnvirons.java.htm) you will notice that it has 
"DefaultErrorReporter.instance" and it seems absolutely valid. For me same 
yuicompressor-2.4.6 is working fine without any issues.

There were some reports in the past about rhino's similar issues and obviously 
the cause was due to incorrect rhino jars. Look at these links if that helps.

http://freemarker.624813.n4.nabble.com/RhinoWrapper-Exception-td626465.html
http://issues.liferay.com/browse/LPS-1822

You can also try this

1. Use intellij, eclipse and do type search (in idea, Ctrl +Shift + N  or in 
eclipse, Ctrl+Shift+T) for "CompilerEnvirons.java" - If you get multiple 
occurrences it means there is another jar (js.jar, rhino.jar or something else) 
causing this.
2. Alternately, You can get source package for rhino and in eclipse/idea do the 
debug with breakpoint to see what is happening. 

Hopefully this will help in finding the real cause.

-
Rajendra

Original comment by rr.patil...@gmail.com on 19 Oct 2011 at 4:55

GoogleCodeExporter commented 8 years ago
Thanks for your input Rajendra. I can see 2 occurrences of CompilerEnvirons in 
the project.
1) From yuicompressor.jar (as expected)
2) From JRE System library RT.jar 
(sun.org.mozilla.javascript.internal.CompilerEnvirons).

In this case what should be done ?

Rahul

Original comment by rahulvat...@gmail.com on 19 Oct 2011 at 6:17

GoogleCodeExporter commented 8 years ago
Its not working for JSON as well.

Original comment by rahulvat...@gmail.com on 19 Oct 2011 at 9:52

GoogleCodeExporter commented 8 years ago
The other CompilerEnvirons from RT.jar should not cause a problem since it is 
from different package. Per your log, the error being thrown by 
"org.mozilla.javascript.CompilerEnvirons" which is from yuicompressor. 

The error I suspect is at this line " errorReporter = 
DefaultErrorReporter.instance;" so may be culprit is 
"DefaultErrorReporter.java". Sorry but I am little doubtful If I will be able 
to you figure out the resolution.  Will let you know if I do. 

Otherwise this file 
https://github.com/sdesai/yuicompressor/blob/master/src/com/yahoo/platform/yui/c
ompressor/JavaScriptCompressor.java#L312, from where exception is chaining, is 
authored by "Julien Lecomte". In case you can consult him about this issue, may 
he knows the problem or hints the fix. You can find his contact details at 
http://www.julienlecomte.net/blog/about-the-author/.

Meanwhile I will keep hunting the solution and will share with you if I get one.

-
Rajendra

Original comment by rr.patil...@gmail.com on 19 Oct 2011 at 12:22

GoogleCodeExporter commented 8 years ago
I think the issue and hence the fix for this is at YUI side. May be not using 
YUIcompressor as maven dependency and manually include the yuicompressor (which 
includes rhino too) helps. 

Closing this for now as Won'tFix.

Original comment by rr.patil...@gmail.com on 8 Dec 2011 at 6:16