jboss 上的 Yui 压缩器 StringIndexOutOfBoundsException
当使用 2.4.6 最小化 yui 时,我遇到了这个问题:
java.lang.StringIndexOutOfBoundsException: String index out of range: 232
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)
当通过我的 IDE 启动时它可以工作,但当部署到 jboss 时却不能。这个地方: http://yuilibrary.com/forum/viewtopic.php?p=20086 有一些同一问题的讨论。
显然,问题在于 org/mozilla/javascript/Parser 位于从我的 Maven 配置中拉入的两个 jar 中:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
有什么方法可以使用 Maven 排除等或通过升级我的 YUI 版本来解决此问题。看起来很愚蠢,它不起作用,而且我不想编写自定义类加载器。
请帮忙!
When minimising yui with 2.4.6, I get this problem:
java.lang.StringIndexOutOfBoundsException: String index out of range: 232
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)
It works when started through my IDE but when deployed to jboss it doesn't. This place: http://yuilibrary.com/forum/viewtopic.php?p=20086 has some discussion of the same problem.
Apparently the issue is around org/mozilla/javascript/Parser being in the two jars that are pulled in from my maven config:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
Is there any way I can solve this using maven exclusions etc. or by upgrading my version of YUI. It seems daft that it just doesn't work and I don't want to have to write a custom classloader.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决方法:对于 JBoss AS 7.1.1.Final 和 YUICompressor 2.4.7
从依赖项中排除 rhino:
为什么?请参阅https://github.com/greenlaw110/greenscript/pull/29#issuecomment-4017147
注意:如果您通过其他方式在类路径中有犀牛,那么您似乎会再次收到此错误。
Workaround: For JBoss AS 7.1.1.Final and YUICompressor 2.4.7
Exclude rhino from dependency:
Why? See https://github.com/greenlaw110/greenscript/pull/29#issuecomment-4017147
Note: if you have a rhino in classpath by some other way, so seems like you'll get this error again.
我通过自己重新打包 yuicompressor 以包含大部分 rhino 源代码解决了这个问题。请参阅我对 Howard M. Lewis Ship 的回复。
重新打包的源代码可以在这里找到: http://viscri.co .uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar。只需将其添加到您的 pom 中:
如果您不运行自己的 Nexus 版本,则必须将其安装在您想要构建的计算机上。我认为这是您需要的命令: http:// maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
您还需要排除 Tapestry 引入的 yuicompressor 版本:
这应该有效。
I solved this problem by repackaging yuicompressor myself to include most of the rhino source. See my reply to Howard M. Lewis Ship.
The repackaged source can be found here : http://viscri.co.uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar. Just add this to your pom:
If you don't run your own version of nexus, you'll have to install it on the machine that you want to build on. This is the command you need I think: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
You'll also need to exclude the yuicompressor version that tapestry pulls in:
This should work.
所选答案的(截至 2014 年 9 月 26 日)jar 已不存在。
因此,我创建了 yuicompressor 的一个分支,其中整个 rhino 包嵌入到 yuicompressor 包中,并将其命名在 yui 下。
https://github.com/timothykim/yuicompressor
只需克隆存储库并运行
ant 获取 jar。
希望这可以帮助其他遇到这个问题的人。
The selected answer's (as of 9/26/2014) jar doesn't exist anymore.
So, I created a fork of yuicompressor where entire rhino package is embedded into the yuicompressor package and namespaced it under yui.
https://github.com/timothykim/yuicompressor
Just clone the repo and run
ant
to obtain the jar.Hope this helps anyone else who stumbles unto this problem.
真的,您在 JBoss 中遇到了类加载器问题吗?
您必须对竞争的 rhino JAR 文件进行某种排除。为什么 Rhino 位于类路径上?它可能是 JBoss 的一个可选功能,您可以关闭它并避免冲突。
Really, you're having class loader problems in JBoss?
You're going to have to do some kind of exclusion on the competing rhino JAR file. Why is Rhino on the classpath? It may be an optional feature of JBoss you can turn off and avoid the conflict that way.