I am having a problem where the YUI Compressor works fine in my IDE and even when I deploy tomcat using the maven goal tomcat:run
, but throws a StringIndexOutOfBoundsException when I run the application as a WAR file:
java.lang.StringIndexOutOfBoundsException: String index out of range: 412
at java.lang.String.substring(String.java:1934)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:267)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:330)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:533)
Now, I know a lot of people have been reporting this problem, such as below: Yui compressor StringIndexOutOfBoundsException on jboss
You can find other people mentioning on other places on the web.
It has been suggested that you need to bundle the rhino files with the yui compressor in the same jar to avoid the classpath error.
I looked further, and I realized that Yahoo released version 2.4.7, which does this. So I included this new version into my project and made sure to remove the other jars, and I still get the same error.
How do I fix this?