需要帮助将GWT库模块打包到JAR中 [英] Need Help Packaging a GWT Library Module into a JAR

查看:110
本文介绍了需要帮助将GWT库模块打包到JAR中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将GWT库模块打包到JAR文件中,并通过将JAR文件添加到其类路径中,将该库用于单独的GWT Web应用程序中。



JAR包含:


  • Java源代码
  • RequestFactory生成的源代码
  • UiBinder生成的源

  • 类文件

  • 库模块描述符
  • UiBinder XML文件
  • li>


库模块继承自Web应用程序:

 <模块> <! - 我的web应用程序的模块描述符 - > 
...
< inherits name =[我的图书馆模块的路径] .Library/>
...
< / module>

但是,我遇到了

 延迟绑定失败,'[路径到mylibrary] .client.ClientFactory'... 

错误,当我尝试启动Web应用程序时,它会在其onModuleLoad()方法中初始化该库。失败是由库模块使用的UiBinder视图和RequestFactory引起的。以开发模式启动或编译Web应用程序会导致错误,并显示错误消息,指出丢失的CSS文件和非法引用emul.java.util包下生成的源代码(我试图在JAR中包括此包和所有其他生成的源代码, )



有人能告诉我需要在JAR中包含哪些内容?使用UiBinder和RequestFactory的库模块是否需要额外的资源?

是否有人成功打包了使用RequestFactory和UiBinder的GWT库模块到一个JAR?



进一步澄清:问题是关于创建一个GWT库模块;一个包含客户端和服务器组件的模块,RequestFactory和UiBinder。请注意,将GWT库模块打包到JAR中,而将具有入口点的常规GWT模块打包到WAR中。我试图从另一个GWT项目中打包这样一个库模块和GWT < inherit> 失败。

解决方案

或者,我误解了您的问题,或者您错误地将GWT编译为Java字节码编译。

传统Java开发


  1. Java源代码被编译为Java字节码.class文件。 >在开发过程中以及在
    部署期间编译.class文件。
  2. 已编译的.class文件可用于
    开发和部署的类路径中
  3. >
  4. 只要位置符合它们各自的
    包名称空间,那么.class文件是jar还是文件夹
    层次结构都无关紧要。

  5. 无法将Java源文件部署到部署类路径
    中,但可以将JSP源文件作为JSP部署到战争中。

GWT并非如此。
$ b


  1. GWT是客户端开发。

  2. GWT被编译成Javascript。

  3. 生成的javascript被打包到一个war文件夹中。
  4. 即编译成可执行文件的GWT是javascript文件。 b
  5. GWT编译要求所有Java类都是源文件。

  6. 您的Java类引用的任何Java库也必须是Java源文件。

GWT战争


  1. 对齐和与服务器端的通信。
  2. 服务器端通常是传统的Java部署到JEE战争结构中。
  3. 因此,部署战争有两个GWT客户端编译为javascript以及JEE .class字节码文件。然而,GWT JavaScript文件与HTML,CSS和其他URL一起放置在战争的URL可见部分,可寻址的资源。

  4. 服务器端编译的java字节码文件或jar被放入类URL和寻址目录中,这些目录不是URL寻址的。


    因此

  5. strong>,



    1. GWT编译的部署结构不能用于开发。 JavaScript的部署战争结构。

    2. 将GWT编译的资源打包到
      jar部署中是没有这样的事情。

    3. 编译GWT资源必须打包到战争的URL可寻址的
      方。

    4. 编译后的JavaScript文件中没有类路径。在JavaScript中的任何类路径概念都是为JSNI的便利而模拟的。

    总结 b

    编译的GWT资源不可用,也不会显示GWT开发,因为...
    GWT开发需要java源代码,并且GWT客户端部署在javascript中处于战争状态,并且javascript不像字节码jars / files。



    因此,在GWT中,打包一个可用于开发和部署的jar的没有这样的东西。一些示例和教程将开发和部署文件打包到一个jar文件中 - 但该jar本质上是一个zip文件,您必须首先从开发文件中拆分部署文件。



    < GWT开发jars =源码罐,

    GWT部署= javascript和资源的战争。



    启动自己的GWT开发,您应该至少有3-6个月的使用JSP,servlet,HTML和JavaScript编写传统JEE应用程序的经验。这可以帮助你灌输服务器端vs客户端的强烈隔离,战争vs jar,从而理解为什么GWT是首先发明的。您将了解部署过程。


    I am trying to package a GWT library module into a JAR file and use the library in a separate GWT web app by adding the JAR file into its class path.

    The JAR contains:

    • Java sources
    • RequestFactory generated sources
    • UiBinder generated sources
    • class files
    • library module descriptor
    • UiBinder XML files

    The library module is inherited from the web app:

    <module> <!-- my web app's module descriptor -->
        ...
        <inherits name="[path to my library module].Library"/>
        ...
    </module>
    

    However, I am running into

    Deferred binding failed for '[path to mylibrary].client.ClientFactory'...
    

    error when I try to launch the web app, which initializes the library in its onModuleLoad() method. The failure is caused by UiBinder views and RequestFactory that the library module uses. Launching in development mode or compiling the web app results in errors with messages stating missing CSS files and illegal references to generated source under emul.java.util package (I tried including this package and all other generated source in the JAR, but it didn't help.)

    Can someone tell me what needs to be included in the JAR? Are there any additional resources required for library modules that use UiBinder and RequestFactory?

    Has anyone successfully packaged a GWT library module that uses RequestFactory and UiBinder into a JAR?

    Further clarification: The question is about creating a GWT library module; a module that includes client and server components, RequestFactory and UiBinder. Note that a GWT library module is packaged into a JAR whereas a regular GWT module with an entry point is packaged into a WAR. My attempts to package such a library module and GWT <inherit> from another GWT project have failed.

    解决方案

    Either, I misunderstand your question, or you mis-correlated GWT compilation with Java byte-code compilation.

    Traditional Java development

    1. Java source is compiled into Java byte-code .class files.
    2. Compiled .class files during development as well as during deployment.
    3. compiled .class files can be used in the classpath of both development and deployment
    4. It does not matter if the .class files are jars or in folder hierarchy as long as their location is compliant to their respective package namespace.
    5. Java source files cannot be deployed into the deployment class path, but you can deploy JSP source files into the war as JSPs.

    Not so for GWT.

    1. GWT is client side development.
    2. GWT is compiled into Javascript.
    3. The resulting javascript are packaged into a war folder.
    4. i.e., GWT compiled into executable files are javascript files.
    5. GWT compilation requires all Java classes to be source files.
    6. Any Java library referenced by your Java classes must also be Java source files.

    GWT war

    1. GWT also facilitates client side alignment and communication with server side.
    2. The server side is normally traditional Java deployed into JEE war structure.
    3. Therefore a deployment war has both GWT client compiled into javascript as well as JEE .class bytecode files.
    4. However, the GWT javascript files are placed in the URL-visible part of the war, together with HTML, CSS and other URL-addressable resources.
    5. Server side compiled java bytecode files or jars are placed into the class and lib directories which are not URL-addressable.

    Therefore,

    1. GWT compiled deployment structures cannot be used for development.
    2. GWT is compiled into javascript deployment war structure.
    3. There is "no such thing" as packaging GWT compiled resources into a jar for deployment.
    4. Compiled GWT resources must be packaged into the URL-addressable side of the war.
    5. There is "no such thing" as classpath in the compiled javascript files. Any classpath concept within javascript is simulated for JSNI's convenience.

    In Conclusion

    Compiled GWT resources are unusable nor will they be visible for GWT development because ... GWT development requires java source, and GWT client deployment are javascript in war, and javascript is not like bytecode jars/files.

    Therefore, in GWT, there is "no such thing" as packaging a jar that is usable for both development and for deployment. Some examples and tutorials do package development and deployment files into a single jar - but that jar is essentially a zip which you have to break up the deployment pieces from the development pieces first.

    GWT Development jars = source jars,

    GWT Deployment = war of javascript and resources.

    Before you launch yourself into GWT development, you should have at least 3-6 months' experience writing traditional JEE apps with JSP, servlets, HTML and javascript. That would help you inculcate a strong sense of segregation of server-side vs client-side, war vs jar and hence understand why GWT was invented in the first place. You would understand the deployment process.

    这篇关于需要帮助将GWT库模块打包到JAR中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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