编译GWT失败 - 没有源代码可用于类型 [英] compile GWT failed - No source code is available for type

查看:133
本文介绍了编译GWT失败 - 没有源代码可用于类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个模块:GWT和Java(SPring等)。
小解释:在Java模块中,我有一个Java邮件发件人方法,我想在我的GWT Widget中使用。这个方法有两个参数: java.util.List< User>收件人字符串消息
有一个例子

 
项目
-GWT
-Java(Spring等)

我需要的东西(在这里您可能会看到我的尝试和下面的代码将代码代码):

1)我想在我的类中调用继承于Composite类的java方法。然后我得到以下错误:

没有源代码可用于类型my.packet.proj.MyClass;你忘了继承一个必需的模块吗?

2)我知道无法在GWT中调用Java代码(不是全部)我用JSNI(我写了一些本地方法)意识到这一点,但对我来说这是不可能的,不幸的是... ...
我有一个代码示例。

  public class MyClass extends Composite {

@UiField
TextBox text;

@UiField
按钮btn;



接口EmailMailingUiBinder扩展了UiBinder< HTMLPanel,MyClass> {
}

private static MyClassUiBinder myUiBinder = GWT.create(MyClassUiBinder.class);
/ * @ param mailService是Java模块中消息传递类的对象* /

public MyClass(MailService mailService){
btn.addClickHandler((event) - > {

sendOnClick(mailService,recipients,message); // code below
});

public native void sendOnClick(MailService mailService,List< User> recipients,String msg)/ * - {
mailService。@ my.packet.proj.MailService :: sendMessage(Ljava / util / list,/ *等等* /)(recipients,msg)
} - * /
}

当Gradle编译Gwt时,上面代码中没有错误。但是我需要在MainPanel中调用它的类(因为它是小部件,页面),当我创建一个MyClass实例时,像这样: new MyClass(new MailService()) compileGwt因编译错误而失败

 没有源代码可用于my.packet.proj.MailService类型;你忘了继承一个必需的模块吗? 

伙计们,你有没有想过如何将实例作为参数传递?



PS我删除了一些不必要的代码
PSS我甚至尝试过这样(创建我的MyClass实例):

pre $ new c MyClass (mailServiceInstance());
$ b $ *和下面的任何地方* /
//这是下面的X行,解释
公共本机MailService mailServiceInstance()/ * - {
return @ my.packet.proj.MailService ::新()();
} - * /;

我在X行有相同的错误

 没有源代码可用于类型my.packet.proj.MailService;你忘了继承一个必需的模块吗? 


解决方案

我认为您误解了GWT的主要基础, GWT在客户端运行,它意味着在浏览器中运行纯JavaScript。因此,要编译为JavaScript的每个Java代码都必须被编写,因为知道运行时是一个具有很多限制的浏览器,而不是标准的JVM。



您想要运行一个发送被认为在JVM中运行的邮件的类,可能是你的 my.packet.proj.MyClass 想要打开套接字来连接到一个smtp服务器等,这是不可能在JS中被模拟的,因为你不能在该服务器上打开一个正常的套接字。这只是您在客户端有大量限制的例子。

因此,所有可以在客户端运行的java代码都来自gwt兼容库,这段代码已经用gwt写在java中,或者可能是一些代码可能最初写在java中并移植到gwt。这些以.jar文件形式提供的库必须包含它的模块定义(gwt.xml)以继承项目,原始的Java源代码等。事实上,GWT编译器不使用字节码(.class)文件,虽然它可能需要在IDE等。



说,为了使用任何不是为GWT编写的Java代码,您必须:


  1. 将它移植到GWT中,创建一个您必须继承的.gwt.xml文件,以前验证所有代码都不会破坏浏览器限制,不依赖于非gwt 3party库等。
  2. 在服务器端运行它,并从浏览器进行ajax调用。


    所以在你的情况中,最简单的方法,我想唯一的办法是,你在.war中包含 my.packet.proj.MyClass ,然后创建您从客户端使用的 RPC服务(或任何ajax解决方案)方面发送邮件。

    I have 2 modules: GWT and Java(SPring etc). Little explanation: In Java module I have a Java Mail Sender method which I want to use in my GWT Widget. That's method has 2 parameters: java.util.List<User> recipients and String message. There is an example

    Project
      -GWT
      -Java(Spring and etc)
    

    What I need(Here you may see my attempts and below will be code what I have):
    1)I want to call java method in my class which was inherited on Composite class. Then I got the following error:
    No source code is available for type my.packet.proj.MyClass; did you forget to inherit a required module?
    2)I learned that it's not possible to call the Java code (not all) in GWT, and I used JSNI(I wrote some native methods) to realize that, but it was impossible to me, unfortunately...
    There is a code example that I had have.

    public class MyClass extends Composite{
    
       @UiField
       TextBox text;
    
       @UiField
       Button btn;
    
    
    
       interface EmailMailingUiBinder extends UiBinder<HTMLPanel, MyClass> {
       }
    
       private static MyClassUiBinder myUiBinder = GWT.create(MyClassUiBinder.class);
       /*@param mailService is an object of messaging class in Java module*/
    
       public MyClass(MailService mailService){
         btn.addClickHandler( (event) ->{
    
         sendOnClick(mailService, recipients ,message); //code below
        });
    
        public native void sendOnClick(MailService mailService, List<User> recipients,   String msg)/*-{
           mailService.@my.packet.proj.MailService::sendMessage(Ljava/util/List,/*and so on*/)(recipients, msg)
         }-*/
    }
    

    There was no errors in code above when Gradle compile Gwt. But I need to call it class(because it's widget, page) in MainPanel, when I create an instance of MyClass, like this: new MyClass(new MailService()) compileGwt FAILED with compilation errors

    No source code is available for type my.packet.proj.MailService; did you forget to inherit a required module?
    

    Guys, do you have any idea how to pass instance as a argument?

    P.S. I removed some unnecessary code P.S.S I even tried like that(to create my Instance of MyClass):

    new MyClass(mailServiceInstance());
    
    /*and anywhere below*/
    //this is a X line below, for explanation
    public native MailService mailServiceInstance()/*-{
            return @my.packet.proj.MailService::new()();
        }-*/;
    

    I have the same error on line X

    No source code is available for type my.packet.proj.MailService; did you forget to inherit a required module?
    

    解决方案

    I think you are misunderstanding the main foundation of GWT, GWT is run in client, it means pure javascript running in a browser. So each java code you want to compile into javascript must be written knowing that the runtime is a browser with a lot of limitations and not the standard JVM.

    You want to run a class to send emails which has been thought to be run in the JVM, probably your my.packet.proj.MyClass wants to open sockets to connect to a smtp server etc, which is impossible to be emulated in JS because you cannot open a normal socket against that server. This is just an example of a large list of limitations you have in client side.

    So, all the java code which can be run in client comes from gwt compliant libraries, this code has been written in java for gwt, or may be some code could be written in java initially and ported to gwt. These libraries delivered in .jar files has to include it's module definitions (gwt.xml) to inherit in your project, the original java source code, etc. In fact the byte code (.class) files are not used by the GWT compiler, although it could be needed in IDE's etc.

    Said that, in order to use any java code not written for GWT, you have to either:

    1. port it to GWT creating a .gwt.xml file which you have to inherit, validating previously that all the code does not break browser limitations, does not depend on non gwt 3party libraries, etc.
    2. run it in server side, and make ajax calls from the browser.

    So in your case the easiest way and I guess the only way, is that you include the my.packet.proj.MyClass in your .war, and create a RPC service (or any ajax solution) which you use from the client side to sent the mail.

    这篇关于编译GWT失败 - 没有源代码可用于类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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