简体   繁体   中英

YUI Compressor throws StringIndexOutOfBoundsException when running in Tomcat from a WAR

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?

If you are using maven build just exclusion rhino or remove js-1.7R2.jar / rhino-1.7R4.jar / rhino-1.7R3.jar file 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 it will solve your problem.

检查你的类路径并删除rhino- .jar(先备份),再试一次我在删除rhino- .jar 后解决了同样的问题

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

Yui compressor StringIndexOutOfBoundsException on jboss

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM