GWT web-app与系统类路径的动态加载类 [英] GWT web-app vs system classpath for dynamic loaded classes

查看:117
本文介绍了GWT web-app与系统类路径的动态加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的GWT网络应用程序中,我将所有jar文件保存在我的项目之外,并使用classpath变量引用它们。这允许我链接到来自其他项目/团队的罐子,而无需将该罐子的副本放在我的Web应用程序li​​b目录中。托管模式善意地在这个系统类路径中查找类,然后将它们添加到Web应用程序类路径中,警告我它正在这样做。当我部署我的构建系统时,只会拉入我需要在我的web应用程序中发布的罐子,并不是问题。



我遇到的问题是一些代码使用动态查找,在类路径中搜索实现。如果一个jar还没有添加到web应用程序的classpath中,因为没有任何类从jar中被加载,它不包含在搜索中。



特殊的问题I拥有持久性 - 它通过搜索META-INF / services文件来查找EntityManagerFactory实现。我也有类似的问题,罗马和它的模块扩展。

我有一个解决方法,在开发/托管模式,我只是指一个我知道的类在我想要的jar中,这会导致它被添加到我的web app classpath中。我这样做是通过调用

  private void devModeClassPathHack(){
Class<?> gwtDevModeHack1 = EntityManagerImpl.class;
}

来自我的开发模式Guice模块。

我的问题很简单 - 是否有更好的方法?

解决方案

我认为,有一个更好的方法 - 使用这种临时的自我修复机制,GWT Jetty / dev模式已经是黑客了:)如果您曾经需要运行服务器端代码即G。 JBoss在开发过程中(与客户端的GWT开发模式一起),这将停止工作。


$ b $(作为一个额外的问题,类加载顺序 - 因此优先级如果在不同的jar包中有多个版本的类 - 将取决于程序流。这可能是非常讨厌的调试。)



你提到,你拉在外面的所有罐子里。在这种情况下,我会做的是将.svnignore(或.gitignore / ...)设置为WEB-INF / lib目录中的* .jar。然后我运行相同的构建步骤,用于创建生成构建,以便在启动服务器之前将jar复制到lib目录中。


In my GWT web app I am keeping all my jar files outside of my project and referencing them using classpath variables. This allows me to link to jars from other projects/teams without having to put a copy of the jar in my web app lib directory. Hosted mode kindly looks up the classes in this system classpath and then adds them to the web-app classpath warning me that it is doing so. When I deploy my build system pulls in only the jars I need to ship in my web app and is not a problem.

The issue I have is that some code uses dynamic lookups, searching the classpath for implementations. If a jar has not yet been added to the web app classpath beacuse no classes have yet benn loaded from the jar it is not included in the search.

The particular problem I am having is with Persistence - it looks up EntityManagerFactory implementations by searching for META-INF/services files. I have also had a similar problem with Rome and its module extensions.

I have got a workaround, in the dev/hosted mode I simply refer to a class I know is in a jar I want and this causes it to be added to my web app classpath. I do this my by calling

private void devModeClassPathHack() {
    Class<?> gwtDevModeHack1 = EntityManagerImpl.class;
}

from my development mode Guice module.

My question is simple - is there a "nicer" way of doing this?

解决方案

I don't think, there's a nicer way - using this makeshift "self-healing" mechanism of the GWT Jetty/dev mode is already a hack :) If you ever have the need to run the server side code on e. g. JBoss during development (together with GWT dev mode for the client side), this will stop working.

(As an additional problem, the order of classloading - and consequently the precedence in cases when there are multiple versions of a class in different jars - will depend on program flow. This can be very nasty to debug.)

You mention, that you pull in all the jars from outside. What I would do in that case, is to set .svnignore (or .gitignore/...) to "*.jar" in the WEB-INF/lib dir. Then I'd run the same build step which is used to create the production build to copy the jars into the lib dir before starting the server.

这篇关于GWT web-app与系统类路径的动态加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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