java - 控制 JAR 在类路径中的加载顺序

标签 java gwt classpath

我将 GWT 2.4 与 gquery-dnd-bundle 1.0.4 结合使用,以便可以通过拖放节点构建树。我遇到了一个恼人的错误(http://code.google.com/p/gwtquery-plugins/issues/detail?id=6)。其要点是我需要保证文件“gquery-dnd-bundle-1.0.4.jar”在运行时由类加载器在 WEB-INF/lib 目录中的 gwt-servlet.jar 文件之前加载。

我如何保证这一点?

如果有用的话,我正在将 Eclipse Indigo 与 GWT Web 应用程序项目结合使用。

这是我看到的确切错误

[ERROR] [draganddroptree] - Errors in 'jar:file:/C:/Documents%20and%20Settings/E18538/workspace/DragAndDropTree/war/WEB-INF/lib/gquery-dnd-bundle-1.0.4.jar!/gwtquery/plugins/droppable/client/gwt/DragAndDropCellTree.java'
        [ERROR] [draganddroptree] - Line 24: The type com.google.gwt.user.cellview.client.CellTreeNodeView is not visible
        [ERROR] [draganddroptree] - Line 86: CellTreeNodeView cannot be resolved to a type
        [ERROR] [draganddroptree] - Line 87: The constructor DragAndDropCellTreeNodeView<T>(DragAndDropCellTree, CellTreeNodeView<?>, TreeViewModel.NodeInfo<T>, Element, T) refers to the missing type CellTreeNodeView
    [ERROR] [draganddroptree] - Unable to load module entry point class com.cme.draganddroptree.client.DragAndDropTree (see associated exception for details)
    [ERROR] [draganddroptree] - Failed to load module 'draganddroptree' from user agent 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1' at localhost:4490

最佳答案

您无法以任何确定的顺序安排“WEB-INF/lib”JAR 的加载。我能想到的唯一可靠的解决方法是将优先级较低的 JAR 文件放在“WEB-INF/lib”之前扫描的目录中。

例如,if you are using Tomcat, then you could :

  1. 将“gwt-servlet.jar”文件放入“$CATALINA_BASE/lib”目录中。
  2. 将“gquery-dnd-bundle-1.0.4.jar”文件保留在 WAR 中。

这样,“gwt-servlet.jar”将首先加载到 CLASSPATH 中,然后“gquery-dnd-bundle-1.0.4.jar”将被加载...覆盖“gwt-”中的任何冲突类servlet.jar”。

如果您使用其他应用服务器,那么服务器级别的“lib”目录将会有所不同...但基本思想是优先级较低的 JAR 需要进入应用服务器的“lib”,而优先级较高的 JAR 需要保留在 Web 应用程序的“lib”中。

这不是世界上最干净的情况,但它会保证你想要的结果。

更新:你知道,在思考并更仔细地重新阅读 Tomcat 文档之后,我实际上可能有这种落后。您可能需要将“gquery-dnd-bundle-1.0.4.jar”放入应用程序服务器“lib”中,并将“gwt-servlet.jar”放入Web应用程序的“lib”中。如果您尝试我的建议并发现其中一种方法比另一种方法更适合您,请告诉我,我将编辑我的答案以使其更加准确。

关于java - 控制 JAR 在类路径中的加载顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7677808/

相关文章:

Java CLASSPATH 不起作用?

java - 计费系统 - 编程

java - 玩!框架 2.0 : How to display multiple image?

java - IntelliJ : Adding a dependency doesn't work but adding to classpath under SDK (Project settings) works

GWT 请求工厂 : How can I get a persistent id from stableId()?

java - GWT中如何连接MySql? (应用引擎)

java - 列出 JRE 上的 Java 虚拟机

java - CPLEX (12.5) Java API,将 LP 解析为 IP

java - Google Drive API - 如何使用域范围服务帐户并从域获取所有文档列表

java - GWT:编辑树项目的文本