1

我刚刚安装了 GWT 2.6,现在收到错误“描述资源路径位置类型文件 war\WEB-INF\lib\gwt-servlet.jar 的大小与 GWT SDK 库 gwt-servlet.jar 不同;也许是不同的版本?gwt-servlet.jar /AwardTracker/war/WEB-INF/lib Unknown Google Web Toolkit Problem"

我下载了 GWT 2.6 zip,然后将目录“GWT-2.6.0”复制到“Eclipse\eclipse-jee-juno-SR1-win32\eclipse\plugins”中。然后我右键单击该项目并选择“properties/Google/Web Toolkit/Configure SDKs.../Add”。然后我浏览到“GWT-2.6.0”目录,添加并选择它。


我遵循了 Braj 的解决方案,并在重新编译时收到以下错误:

编译模块 org.AwardTracker.AwardTracker 验证单元:在第一次通过时忽略 2 个编译错误的单元。编译时使用 -strict 或将 -logLevel 设置为 TRACE 或 DEBUG 以查看所有错误。计算 'gwtupload.client.DecoratedFileUpload.DecoratedFileUploadImpl' 的所有可能的重新绑定结果 重新绑定 gwtupload.client.DecoratedFileUpload.DecoratedFileUploadImpl 找不到完全匹配的规则。使用基于回退值的“最近”规则。您可能需要实现特定的绑定,以防回退行为无法替换缺少的绑定' 不能是抽象的

通过下载 gwtupload-1.0.1.jar,使用“添加外部 JARS”将其添加到库并删除旧的 gwtupload-0.6.6.jar 来修复上述问题。然后我重新编译并编译工作。但是,现在我的“MyCustomisedUploadServlet”中有一个错误(这个错误以前不存在):

 protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found</" + TAG_ERROR + ">";

其余的代码是:

package org.AwardTracker.server;

import gwtupload.server.UploadAction;
import gwtupload.server.exceptions.UploadActionException;
import gwtupload.shared.UConsts;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;

/**
 * This is an example of how to use UploadAction class.
 *  
 * This servlet saves all received files in a temporary folder, 
 * and deletes them when the user sends a remove request.
 * 
 * @author Manolo Carrasco Moñino
 *
 */
public class MyCustomisedUploadServlet extends UploadAction {

  private static final long serialVersionUID = 1L;
  protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found</" + TAG_ERROR + ">";

  Hashtable<String, String> receivedContentTypes = new Hashtable<String, String>();
  /**
   * Maintain a list with received files and their content types. 
   */
  Hashtable<String, File> receivedFiles = new Hashtable<String, File>();

  /**
   * Override executeAction to save the received files in a custom place
   * and delete this items from session.  
   */
  @Override
  public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {
    String response = "";
    @SuppressWarnings("unused")
    int cont = 0;
    for (FileItem item : sessionFiles) {
      if (false == item.isFormField()) {
        cont ++;
        try {

          /// Create a temporary file placed in the default system temp folder
          File file = File.createTempFile("upload-", ".bin");
          item.write(file);

          /// Save a list with the received files
          receivedFiles.put(item.getFieldName(), file);
          receivedContentTypes.put(item.getFieldName(), item.getContentType());

          /// Send a customised message to the client.
          response += file.getAbsolutePath();

        } catch (Exception e) {
          throw new UploadActionException(e);
        }
      }
    }

    /// Remove files from session because we have a copy of them
    removeSessionFileItems(request);

    /// Send your customised message to the client.
    return response;
  }

  /**
   * Get the content of an uploaded file.
   */
  @Override
  public void getUploadedFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String fieldName = request.getParameter(UConsts.PARAM_SHOW);
    File f = receivedFiles.get(fieldName);
    if (f != null) {
      response.setContentType(receivedContentTypes.get(fieldName));
      FileInputStream is = new FileInputStream(f);
      copyFromInputStreamToOutputStream(is, response.getOutputStream());
    } else {
      renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND);
   }
  }

  /**
   * Remove a file when the user sends a delete request.
   */
  @Override
  public void removeItem(HttpServletRequest request, String fieldName)  throws UploadActionException {
    File file = receivedFiles.get(fieldName);
    receivedFiles.remove(fieldName);
    receivedContentTypes.remove(fieldName);
    if (file != null) {
      file.delete();
    }
  }
}

我只是将这一行注释掉(“protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found";"),重新编译并运行它,它工作正常。我希望这一切对其他人有所帮助。感谢 Braj 的帮助。

4

4 回答 4

7

这对我很有用

选择警告,右键单击并选择“快速修复”->“将 /WEB-INF/lib 与 SDK 库同步”

“完毕”

于 2015-05-08T08:17:34.740 回答
5

每当您更改 GWT 版本时,您必须从由先前 GWT 版本自动生成的存根中清除您的项目,如下面的屏幕截图所示。

问题:文件war\WEB-INF\lib\gwt-servlet.jar的大小与 GWT SDK 库不同gwt-servlet.jar;也许它是一个不同的版本?

解决方案:您的问题是gwt-servlet.jar由以前的 GWT 版本自动生成的。只需将其与其他存根一起删除并再次重新编译项目即可。

在此处输入图像描述

于 2014-05-04T12:37:34.813 回答
2

复制插件目录中的 sdk 不是添加另一个 SDK 版本的正确方法。

使用 Preferences -> Google -> Web Toolkit 添加另一个 GWT SDK 版本。

在您的项目中选择:

项目属性 -> Goolge -> Web Toolkit 你可以选择项目应该使用的 SDK。

于 2014-05-04T11:50:55.013 回答
0

我将编译器从 1.8 更改为 1.7 并丢失了此消息。

于 2014-11-04T19:59:57.460 回答