用jwrapper构建的jar无法正常工作 [英] jar built with jwrapper doesn't work

查看:108
本文介绍了用jwrapper构建的jar无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jwrapper会以某种方式操纵应用程序jar,并导致jar无法运行:在运行时,它将引发无法将MyClass强制转换为MyClass"类型错误.我认为,这是由于重新评估创建类加载器的代码导致的,从而导致类MyClass的多个实例被加载.

jwrapper manipulates application jars somehow, and is resulting in a non-functioning jar: at runtime it throws a "MyClass cannot be cast to MyClass" type error. I believe this is caused by re-evaluating code that creates a class loader, leading to multiple instances of class MyClass being loaded.

除了使用pack200之外,jwrapper文档没有描述对jar所做的更改.我已经单独测试了pack200,它不会导致此问题.

The jwrapper docs don't describe the changes made to the jar, except for the use of pack200. I've tested pack200 in isolation, and it does not cause this problem.

我还通过将jwrapper传递给"java -jar"来测试由jwrapper构建的jar,而无需使用wrapper可执行文件.因此,这不是jvm转换,也不是包装程序正在执行的任何其他操作:jar本身已损坏.

I've also tested the jar built by jwrapper without using the wrapper executable, by passing it to "java -jar". So it's not jvm transmuting, or anything else that the wrapper is doing: the jar itself is broken.

更新:

jwrapper允许跳过pack200,但是安装文件很大.由于pack200可以在独立运行时运行,因此,如果可以通过某种方式告诉jwrapper文件已经打包,则可以解决此问题.使用< Pack200Exceptions>没有帮助,因为那时它不知道文件已打包.

jwrapper allows skipping pack200, but then the install file is huge. Since pack200 works when run standalone, I could work around this if there were some way to tell jwrapper that the file is already packed. Using <Pack200Exceptions> doesn't help, because then it doesn't know the file is packed.

推荐答案

潜在的问题是jwrapper将pack200选项"modification_time"设置为"latest",这会更改所有类文件的修改时间.在运行时,这会导致clojure编译器尝试从源代码重新编译类.

The underlying problem is that jwrapper sets the pack200 option "modification_time" to "latest", which changes the modification times of all the class files. At run-time this causes the clojure compiler to attempt to recompile the classes from source.

一种解决方法是在打包之前从jar中删除.clj文件,以防止编译器运行. lein的:omit-source"选项在这里是不够的,因为它从任何依赖项保留在.clj文件中.相反,您必须在:uberjar-exclusions中使用模式,例如

A work-around is to remove the .clj files from the jar prior to packaging, preventing the compiler from running. The lein ":omit-source" option is not sufficient here, because it leaves in .clj files from any dependencies. Instead you must use a pattern in :uberjar-exclusions, e.g.

:uberjar排除项[#.(clj | java)"]

:uberjar-exclusions [#".(clj|java)"]

如此处所述:

https://github.com/technomancy/leiningen/issues/1357

这篇关于用jwrapper构建的jar无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆