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

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

问题描述

在我的 GWT Web 应用程序中,我将所有 jar 文件保留在我的项目之外,并使用类路径变量引用它们.这使我可以链接到来自其他项目/团队的 jar,而无需将 jar 的副本放在我的 Web 应用程序 lib 目录中.托管模式会在此系统类路径中查找类,然后将它们添加到 web-app 类路径中,警告我它正在这样做.当我部署我的构建系统时,只提取我需要在我的网络应用程序中发送的 jar,这不是问题.

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.

我遇到的问题是某些代码使用动态查找,在类路径中搜索实现.如果 jar 尚未添加到 Web 应用程序类路径,因为尚未从 jar 加载任何类,则不会将其包含在搜索中.

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.

我遇到的特殊问题是 Persistence - 它通过搜索 META-INF/services 文件来查找 EntityManagerFactory 实现.我在 Rome 及其模块扩展中也遇到了类似的问题.

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.

我有一个解决方法,在开发/托管模式下,我只是引用一个我知道在我想要的 jar 中的类,这会导致它被添加到我的 Web 应用程序类路径中.我通过打电话来做到这一点

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;
}

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

from my development mode Guice module.

我的问题很简单 - 有没有更好"的方法来做到这一点?

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

推荐答案

我不认为,还有更好的方法 - 使用 GWT Jetty/dev 模式的这种临时自我修复"机制已经是一种黑客 :)如果您需要在 e 上运行服务器端代码.G.JBoss 在开发期间(连同客户端的 GWT 开发模式),这将停止工作.

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.

(作为一个额外的问题,类加载的顺序 - 以及在不同 jar 中有多个版本的类的情况下的优先级 - 将取决于程序流程.这可能非常难以调试.)

(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.)

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

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 应用程序与系统类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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