如何在GWT(Google Web Toolkit)项目中包含外部jar? [英] How to include a external jar in a GWT (Google Web Toolkit) project?

查看:84
本文介绍了如何在GWT(Google Web Toolkit)项目中包含外部jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为xxx.jar的外部jar文件。我在我的GWT项目中使用了xxx.jar。

当我尝试在Ant中构建项目的JavaScript版本时,出现以下错误类型之一在我使用xxx的每个位置。在Ant中执行gwtc任务时出现此类错误,javac编译过程进行得很顺利。



[错误]第45行:没有源代码可用于类型org.xxx.ObjectName;你忘了继承一个必需的模块吗?


好的,很明显它不能看到/使用xxx.jar。然而,解决这个问题在GWT中并不像在普通java中那么简单。来自互联网 ref1 ,我得知我需要


  1. 包含所有源文件(.java) xxx.jar放入源目录

  2. 在某种新的gwt.xml文件中添加此源目录

  3. 希望并祈祷所有的java文件可以通过GWT进行翻译:/ b / b

    $所以...我究竟做了什么?什么是我需要生成的这个gwt.xml文件(第2步)?我在哪里放源目录,以及如何引用它(步骤1)?什么是在GWT中添加外部jar文件所需的机械步骤?

    解决方案

    因为您的GWT源代码已被编译为JavaScript可以在客户端浏览器上工作,因此GWT编译器应该可以使用源代码。



    查看Lars Vogels 文章,在他的教程中有关于此的简要部分



    这也是有道理的,由于 Google Outline 即使您可以获得源代码,此JAR中的所有代码都不会编译为GWT javascript。 Java b $ b标准版和企业版
    库中可用的
    类的一小部分,作为这些库是
    非常大,并且依赖于web
    浏览器中不可用的功能
    。要了解
    核心Java运行时软件包支持哪些
    类和方法,请参阅
    GWT JRE Emulation Reference

    Robert Hanson一步一步提供在如何打包GWT组件, p>

    祝您好运......

    I have a external jar file named "xxx.jar". I use "xxx.jar" in my GWT project.

    When I attempt to build the JavaScript version of my project in Ant, I get one of the following type of errors at every location in which I use xxx. I get a error of this kind when doing the "gwtc" task in Ant, the javac compilation process proceeds just fine.

    [ERROR] Line 45: No source code is available for type org.xxx.ObjectName; did you forget to inherit a required module?

    Ok, so clearly it is not able to see/use the xxx.jar. Fixing this problem however is not as simple in GWT as it is in "plain" java. From the internet ref1, I gather that I need to

    1. Include all the source (.java) files from xxx.jar in a source directory
    2. Add this source directory in some sort of new gwt.xml file
    3. Hope and pray that all the java files are translatable by GWT :/

    So... What exactly do I do? what is this gwt.xml file I need to generate (Step 2)? Where do I put the source directory, and how to I reference it (Step 1)? What exactly are the mechanical steps necessary to add a external jar file in GWT?

    解决方案

    Because your GWT source has to be compiled to JavaScript to work on the client side browser it makes sense that the source code should be available to the GWT compiler.

    Check out Lars Vogels article with a brief section on this in his tutorial

    It also makes sense, due to the restrictions that Google Outline that all of the code in this JAR may not compile to GWT javascript even if you can get the source.

    GWT supports only a small subset of the classes available in the Java 2 Standard and Enterprise Edition libraries, as these libraries are quite large and rely on functionality that is unavailable within web browsers. To find out exactly which classes and methods are supported for core Java runtime packages, see the GWT JRE Emulation Reference

    Robert Hanson provides a step by step on how to package GWT components

    Good Luck...

    这篇关于如何在GWT(Google Web Toolkit)项目中包含外部jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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