问题
I'm using GWT 2.4 with gquery-dnd-bundle 1.0.4 so that I can construct trees with drag-and-drop nodes. I've bumped into an annoying bug (http://code.google.com/p/gwtquery-plugins/issues/detail?id=6). The gist of it is I need to guarantee that the file "gquery-dnd-bundle-1.0.4.jar" gets loaded by the classloader at runtime before the gwt-servlet.jar file in my WEB-INF/lib directory.
How can I guarantee this?
I'm using Eclipse Indigo with a GWT Web Application project if that is useful.
Here's the exact error I'm seeing
[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
回答1:
You cannot arrange the loading of your "WEB-INF/lib" JAR's in any kind of deterministic order. The only surefire workaround I can think of is to place the lower-priority JAR file in a directory that is scanned prior to "WEB-INF/lib".
For example, if you are using Tomcat, then you could:
- Place the "gwt-servlet.jar" file in the "$CATALINA_BASE/lib" directory.
- Keep the "gquery-dnd-bundle-1.0.4.jar" file inside your WAR.
This way, "gwt-servlet.jar" will be loaded into the CLASSPATH first, and "gquery-dnd-bundle-1.0.4.jar" will be loaded second... overwriting any conflicting classes from "gwt-servlet.jar".
If you are using some other app server, then the server-level "lib" directory will be different... but the basic idea is that the lower-priority JAR needs to go into the app server's "lib", while the higher-priority JAR needs to stay in the webapp's "lib".
Not the cleanest situation in the world, but it will guarantee the result you want.
UPDATE: You know, after thinking about it and re-reading the Tomcat docs more carefully, I may actually have this backward. You may need to put "gquery-dnd-bundle-1.0.4.jar" in your app server "lib", and "gwt-servlet.jar" in your webapp's "lib". If you try my suggestion and find that it works for you with one approach over the other, let me know and I'll edit my answer to be more precise.
回答2:
To solve this bug you should have gquery-dnd-bundle-1.0.4.jar set before GWT in your classpath. Using Eclipse in your project properties go to Java Build Path / Order an export and make sure gquery lib is before GWT.
Anyway you may have another problem as gquery-dnd-bundle-1.0.4.jar is compatible with GWT 2.3.x and you are using GWT 2.4. Until a new release of dnd-bundle you can use the enhance-plugin-1.0.2.jar (contains the DND bundle) and gwtquery-1.1.0-SNAPSHOT.jar.
You should look also at the native drag and drop support added in GWT 2.4. Documentation is scarce, but I found this example (you can drag templates from the right and drop them in the task details), and the relevant source code. (info from this post)
来源:https://stackoverflow.com/questions/7677808/controlling-the-order-of-how-jars-are-loaded-in-the-classpath