GWT RPC 无法编译项目

发布于 2025-01-02 04:37:21 字数 6573 浏览 1 评论 0原文

这个问题是上一个问题的延伸。 GWT 无法编译项目

请查看并告诉我出了什么问题。

客户端。

Twitter.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
*/
public class Twitter implements EntryPoint {


private final TwitterServiceAsync searchService = GWT.create(TwitterService.class);

public void onModuleLoad() {

     // Create a Flex Table
    final FlexTable flexTable = new FlexTable();
    FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
    flexTable.addStyleName("cw-FlexTable");
    flexTable.setWidth("32em");
    flexTable.setCellSpacing(5);
    flexTable.setCellPadding(3);

    // Add some text
    cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
    cellFormatter.setColSpan(0, 0, 2);

    searchService.search("love", new AsyncCallback<ArrayList<Tweet>>() {

        @Override
        public void onFailure(Throwable caught) {
            //Not yet completed.

        }

        @Override
        public void onSuccess(ArrayList<Tweet> result) {
            for (int i=0 ; i <result.size() ; i++) {
                Tweet tweet = result.get(i);
                String user = tweet.getFromUser();
                String status = tweet.getText();
                addRow(flexTable, user);
                addRow(flexTable, status);

        }


    }});


    flexTable.ensureDebugId("cwFlexTable");
    RootPanel.get().add(flexTable);
  }

  /**
   * Add a row to the flex table.
   */
  private void addRow(FlexTable flexTable, String status) {
    int numRows = flexTable.getRowCount();
    flexTable.setText(numRows, 0, status);
    flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
  }

  /**
   * Remove a row from the flex table.
   */
  private void removeRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();
    if (numRows > 1) {
      flexTable.removeRow(numRows - 1);
      flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows - 1);
    }

}
}

TwitterService.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("search")
 public interface TwitterService extends RemoteService {
ArrayList<Tweet> search(String searchTerm) throws IllegalArgumentException;
}

TwitterServiceAsync.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface TwitterServiceAsync {

void search(String searchTerm, AsyncCallback<ArrayList<Tweet>> callback) throws llegalArgumentException;
}

服务器端

package in.isuru.twitter.server;

import java.util.ArrayList;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import in.isuru.twitter.client.TwitterService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class TwitterServiceImpl extends RemoteServiceServlet implements TwitterService {

/**
 * 
 */
private static final long serialVersionUID = 1L;

ArrayList<Tweet> tweets = new ArrayList<Tweet>();

@Override
public ArrayList<Tweet> search(String searchTerm) {
    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    Query query = new Query(searchTerm);
    QueryResult result = null;
    try {
        result = twitter.search(query);
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    for (Tweet tweet : result.getTweets()) {
        //System.out.println(tweet.getFromUser() + ":" + tweet.getText());
        tweets.add(tweet);

    }

    return tweets;
}

 }

Twitter.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='twitter'>
 <!-- Inherit the core Web Toolkit stuff.                        -->
 <inherits name='com.google.gwt.user.User'/>

 <!-- Inherit the default GWT style sheet.  You can change       -->
 <!-- the theme of your GWT application by uncommenting          -->
 <!-- any one of the following lines.                            -->
 <inherits name='com.google.gwt.user.theme.clean.Clean'/>
 <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->


 <!-- Other module inherits                                      -->

 <!-- Specify the app entry point class.                         -->
 <entry-point class='in.isuru.twitter.client.Twitter'/>

 <!-- Specify the paths for translatable code                    -->
 <source path='client'/>
<source path='shared'/>

</module>

错误是

[DEBUG] [twitter] - 验证新编译的单元 [TRACE] [twitter]
- 查找入口点类 [错误] [twitter] - “file:/E:/workspace/Twitter/src/in/isuru/twitter/client/Twitter.java”中的错误
[错误] [twitter] - 第 43 行:没有可用于类型的源代码
twitter4j.Tweet;您是否忘记继承所需的模块? [错误]
[twitter] - 错误
'文件:/E:/workspace/Twitter/src/in/isuru/twitter/client/TwitterServiceAsync.java'
[错误] [twitter] - 第 11 行:没有可用于类型的源代码
twitter4j.Tweet;您是否忘记继承所需的模块? [错误]
[twitter] - 无法找到类型“in.isuru.twitter.client.Twitter”
[错误] [twitter] - 提示:以前的编译器错误可能已经发生
此类型不可用 [错误] [twitter] - 提示:检查
来自模块的继承链;它可能不会继承
所需的模块或模块可能未添加其源路径条目
正确[错误] [twitter] - 无法从用户加载模块“twitter”
代理'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7(KHTML,例如
Gecko) Chrome/16.0.912.77 Safari/535.7' at 127.0.0.1:7901

This question is an extension of previous question. GWT Cannot compile the project

Please have a look and tell me what's wrong with it.

Client side.

Twitter.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
*/
public class Twitter implements EntryPoint {


private final TwitterServiceAsync searchService = GWT.create(TwitterService.class);

public void onModuleLoad() {

     // Create a Flex Table
    final FlexTable flexTable = new FlexTable();
    FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
    flexTable.addStyleName("cw-FlexTable");
    flexTable.setWidth("32em");
    flexTable.setCellSpacing(5);
    flexTable.setCellPadding(3);

    // Add some text
    cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
    cellFormatter.setColSpan(0, 0, 2);

    searchService.search("love", new AsyncCallback<ArrayList<Tweet>>() {

        @Override
        public void onFailure(Throwable caught) {
            //Not yet completed.

        }

        @Override
        public void onSuccess(ArrayList<Tweet> result) {
            for (int i=0 ; i <result.size() ; i++) {
                Tweet tweet = result.get(i);
                String user = tweet.getFromUser();
                String status = tweet.getText();
                addRow(flexTable, user);
                addRow(flexTable, status);

        }


    }});


    flexTable.ensureDebugId("cwFlexTable");
    RootPanel.get().add(flexTable);
  }

  /**
   * Add a row to the flex table.
   */
  private void addRow(FlexTable flexTable, String status) {
    int numRows = flexTable.getRowCount();
    flexTable.setText(numRows, 0, status);
    flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
  }

  /**
   * Remove a row from the flex table.
   */
  private void removeRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();
    if (numRows > 1) {
      flexTable.removeRow(numRows - 1);
      flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows - 1);
    }

}
}

TwitterService.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("search")
 public interface TwitterService extends RemoteService {
ArrayList<Tweet> search(String searchTerm) throws IllegalArgumentException;
}

TwitterServiceAsync.java

package in.isuru.twitter.client;

import java.util.ArrayList;

import twitter4j.Tweet;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface TwitterServiceAsync {

void search(String searchTerm, AsyncCallback<ArrayList<Tweet>> callback) throws llegalArgumentException;
}

Server Side

package in.isuru.twitter.server;

import java.util.ArrayList;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import in.isuru.twitter.client.TwitterService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class TwitterServiceImpl extends RemoteServiceServlet implements TwitterService {

/**
 * 
 */
private static final long serialVersionUID = 1L;

ArrayList<Tweet> tweets = new ArrayList<Tweet>();

@Override
public ArrayList<Tweet> search(String searchTerm) {
    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    Query query = new Query(searchTerm);
    QueryResult result = null;
    try {
        result = twitter.search(query);
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    for (Tweet tweet : result.getTweets()) {
        //System.out.println(tweet.getFromUser() + ":" + tweet.getText());
        tweets.add(tweet);

    }

    return tweets;
}

 }

Twitter.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='twitter'>
 <!-- Inherit the core Web Toolkit stuff.                        -->
 <inherits name='com.google.gwt.user.User'/>

 <!-- Inherit the default GWT style sheet.  You can change       -->
 <!-- the theme of your GWT application by uncommenting          -->
 <!-- any one of the following lines.                            -->
 <inherits name='com.google.gwt.user.theme.clean.Clean'/>
 <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
 <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->


 <!-- Other module inherits                                      -->

 <!-- Specify the app entry point class.                         -->
 <entry-point class='in.isuru.twitter.client.Twitter'/>

 <!-- Specify the paths for translatable code                    -->
 <source path='client'/>
<source path='shared'/>

</module>

Error is

[DEBUG] [twitter] - Validating newly compiled units [TRACE] [twitter]
- Finding entry point classes [ERROR] [twitter] - Errors in 'file:/E:/workspace/Twitter/src/in/isuru/twitter/client/Twitter.java'
[ERROR] [twitter] - Line 43: No source code is available for type
twitter4j.Tweet; did you forget to inherit a required module? [ERROR]
[twitter] - Errors in
'file:/E:/workspace/Twitter/src/in/isuru/twitter/client/TwitterServiceAsync.java'
[ERROR] [twitter] - Line 11: No source code is available for type
twitter4j.Tweet; did you forget to inherit a required module? [ERROR]
[twitter] - Unable to find type 'in.isuru.twitter.client.Twitter'
[ERROR] [twitter] - Hint: Previous compiler errors may have made
this type unavailable [ERROR] [twitter] - Hint: Check the
inheritance chain from your module; it may not be inheriting a
required module or a module may not be adding its source path entries
properly [ERROR] [twitter] - Failed to load module 'twitter' from user
agent 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like
Gecko) Chrome/16.0.912.77 Safari/535.7' at 127.0.0.1:7901

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深巷少女 2025-01-09 04:37:21

twitter4j.Tweet 不能在客户端代码中使用,因为它不包含在任何继承的 GWT 模块中。您需要创建自己的传输对象类,例如 clientshared 包中的某个位置的 TweetDTO。仅应在接口 TwitterServiceAsyncTwitterService 中使用此对象。然后在您的 servlet 中,创建 TweetDTO,将所需值从 Tweet 复制到 TweetDTO,然后返回 TweetDTO 列表。

class twitter4j.Tweet cannot be used in client code since it is not included in any inherited GWT module. You need to create your own transfer object class, for example TweetDTO somewhere in your client or shared packages. Only this object should be used in interfaces TwitterServiceAsync and TwitterService. Then in your servlet, you create TweetDTO copy required values from Tweet to TweetDTO and then return a list of TweetDTO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文