YUI compressor throws a StringIndexOutOfBoundsException when launched in Tomcat from WAR

I had a problem when the YUI Compressor works fine in my IDE and even when I deploy tomcat using the maven tomcat:run target but throw a StringIndexOutOfBoundsException when launching 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 that many people have reported this problem, for example below: Yui Compressor StringIndexOutOfBoundsException on jboss

You can find other people who are mentioned elsewhere on the Internet.

It has been suggested that you need to link the rhino files with the yui compressor in the same bank in order to avoid a class path error.

I looked further, and I realized that Yahoo has released version 2.4.7, which does this. Therefore, I included this new version in my project and made sure that I delete other banks, and I still get the same error.

How to fix it?

+4
source share
3 answers

If you use maven build just exclusion rhino or delete the js-1.7R2.jar / rhino-1.7R4.jar / rhino-1.7R3.jar from your classpath ,

 <dependency> <groupId>com.yahoo.platform.yui</groupId> <artifactId>yuicompressor</artifactId> <version>2.4.7</version> <exclusions> <exclusion> <artifactId>js</artifactId> <groupId>rhino</groupId> </exclusion> </exclusions> </dependency> 

Hope this solves your problem.

+4
source

check your classpath and remove rhino- .jar (back up first), try again. I solved the same problem after removing the rhino - .jar.

+2
source

This question should solve your problem, especially if you are using maven:

Compressor Yui StringIndexOutOfBoundsException on jboss

+1
source

Source: https://habr.com/ru/post/1385311/


All Articles