简体   繁体   English

需要帮助将GWT库模块打包到JAR中

[英]Need Help Packaging a GWT Library Module into a JAR

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. 我正在尝试将GWT库模块打包到JAR文件中,并通过将JAR文件添加到其类路径中,在单独的GWT Web应用程序中使用该库。

The JAR contains: JAR包含:

  • Java sources Java来源
  • RequestFactory generated sources RequestFactory生成的源
  • UiBinder generated sources UiBinder产生了消息来源
  • class files 类文件
  • library module descriptor 库模块描述符
  • UiBinder XML files UiBinder XML文件

The library module is inherited from the web app: 库模块继承自Web应用程序:

<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. 我尝试启动Web应用程序时出错,该应用程序在其onModuleLoad()方法中初始化库。 The failure is caused by UiBinder views and RequestFactory that the library module uses. 失败是由库模块使用的UiBinder视图和RequestFactory引起的。 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.) 在开发模式下启动或编译Web应用程序会导致错误,消息显示缺少CSS文件以及在emul.java.util包下对生成的源的非法引用(我尝试在JAR中包含此包和所有其他生成的源,但它没有'帮忙。)

Can someone tell me what needs to be included in the JAR? 有人可以告诉我需要包含在JAR中的内容吗? Are there any additional resources required for library modules that use UiBinder and RequestFactory? 使用UiBinder和RequestFactory的库模块是否还需要其他资源?

Has anyone successfully packaged a GWT library module that uses RequestFactory and UiBinder into a JAR? 有没有人成功打包过一个将RequestFactory和UiBinder用于JAR的GWT库模块?

Further clarification: The question is about creating a GWT library module; 进一步澄清:问题是关于创建GWT库模块; a module that includes client and server components, RequestFactory and UiBinder. 包含客户端和服务器组件的模块,RequestFactory和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. 请注意,GWT库模块打包到JAR中,而带有入口点的常规GWT模块打包到WAR中。 My attempts to package such a library module and GWT <inherit> from another GWT project have failed. 我尝试从另一个GWT项目打包这样的库模块和GWT <inherit>失败了。

Either, I misunderstand your question, or you mis-correlated GWT compilation with Java byte-code compilation. 或者,我误解了你的问题,或者你错误地将GWT编译与Java字节码编译相关联。

Traditional Java development 传统的Java开发

  1. Java source is compiled into Java byte-code .class files. Java源代码被编译为Java字节码.class文件。
  2. Compiled .class files during development as well as during deployment. 在开发期间以及部署期间编译的.class文件。
  3. compiled .class files can be used in the classpath of both development and deployment 编译的.class文件可以在开发和部署的类路径中使用
  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. 无论.class文件是jar还是文件夹层次结构都没关系,只要它们的位置符合各自的包命名空间即可。
  5. Java source files cannot be deployed into the deployment class path, but you can deploy JSP source files into the war as JSPs. Java源文件无法部署到部署类路径中,但您可以将JSP源文件作为JSP部署到war中。

Not so for GWT. 对于GWT来说并非如此。

  1. GWT is client side development. GWT是客户端开发。
  2. GWT is compiled into Javascript. GWT编译成Javascript。
  3. The resulting javascript are packaged into a war folder. 生成的javascript打包到war文件夹中。
  4. ie, GWT compiled into executable files are javascript files. 即,编译成可执行文件的GWT是javascript文件。
  5. GWT compilation requires all Java classes to be source files. GWT编译要求所有Java类都是源文件。
  6. Any Java library referenced by your Java classes must also be Java source files. Java类引用的任何Java库也必须是Java源文件。

GWT war GWT战争

  1. GWT also facilitates client side alignment and communication with server side. GWT还有助于客户端与服务器端的对齐和通信。
  2. The server side is normally traditional Java deployed into JEE war structure. 服务器端通常是传统的Java部署到JEE战争结构中。
  3. Therefore a deployment war has both GWT client compiled into javascript as well as JEE .class bytecode files. 因此,部署战争将GWT客户端编译为javascript以及JEE .class字节码文件。
  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. 但是,GWT javascript文件与HTML,CSS和其他URL可寻址资源一起放在战争的URL可见部分。
  5. Server side compiled java bytecode files or jars are placed into the class and lib directories which are not URL-addressable. 服务器端编译的java字节码文件或jar放置在不能URL寻址的类和lib目录中。

Therefore , 因此

  1. GWT compiled deployment structures cannot be used for development. GWT编译的部署结构不能用于开发。
  2. GWT is compiled into javascript deployment war structure. GWT被编译成javascript部署战结构。
  3. There is "no such thing" as packaging GWT compiled resources into a jar for deployment. 将GWT编译资源打包到jar中进行部署是“没有这样的事情”。
  4. Compiled GWT resources must be packaged into the URL-addressable side of the war. 必须将编译的GWT资源打包到战争的URL可寻址端。
  5. There is "no such thing" as classpath in the compiled javascript files. 编译的javascript文件中有类似路径的“没有这样的东西”。 Any classpath concept within javascript is simulated for JSNI's convenience. javascript中的任何类路径概念都是为JSNI的方便而模拟的。

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. 编译的GWT资源不可用也不会对GWT开发可见因为...... GWT开发需要java源,GWT客户端部署是javascript in war,而javascript不像字节码jar /文件。

Therefore, in GWT, there is "no such thing" as packaging a jar that is usable for both development and for deployment. 因此,在GWT中,包装可用于开发和部署的jar的“没有这样的东西”。 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. 一些示例和教程将开发和部署文件打包到一个jar中 - 但该jar本质上是一个zip,您必须先从开发部分拆分部署部分。

GWT Development jars = source jars, GWT开发罐子=源罐子,

GWT Deployment = war of javascript and resources. GWT部署= javascript和资源的战争。

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. 在开始进入GWT开发之前,您应该至少有3-6个月的经验,使用JSP,servlet,HTML和javascript编写传统的JEE应用程序。 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. 这将有助于你灌输强烈的服务器端与客户端,战争与jar的隔离感,从而理解为什么GWT首先被发明。 You would understand the deployment process. 您将了解部署过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM