简体   繁体   English

如何在没有 Maven 的情况下结合 GWT 和 Material Design Library?

[英]How to combine GWT and Material Design Library w/o Maven?

I was trying to use the MD-Library from Central Maven Repo by just downloading the jar's and just using a normal Java-Project in Eclipse .我试图通过仅下载 jar 并在Eclipse中使用普通的 Java 项目来使用Central Maven Repo的 MD-Library。

From the Central Maven Repo I used the jar gwt-material and since it said during compilation I need MD-jQuery-lib as well, I integrated that jar for gwt-material-jQuery , too.Central Maven Repo我使用了 jar gwt-material ,因为它在编译期间说我也需要 MD-jQuery-lib,所以我也为gwt-material-jQuery集成了那个 jar。

So following you will find那么跟着你会发现

  • gwt.xml: where I inherit all the required libraries for the gwt-project gwt.xml:我在这里继承了 gwt 项目所需的所有库
  • the entryPoint-class ( Addressbook2 ) with onModuleLoad() -method带有onModuleLoad()方法的 entryPoint 类 ( Addressbook2 )
  • UIBinder-class, of which an instance should be added in the entryPoint-class UIBinder类,在entryPoint类中添加一个实例
  • UIBinder.ui.xml-file where the MatDes-Lib is integrated as resource-field UIBinder.ui.xml 文件,其中 MatDes-Lib 被集成为资源字段

Sorry in advance for such a huge post.对于这么大的帖子,提前致歉。 Did not know how to pack it more compact.不知道如何包装得更紧凑。

So running and compiling this in Eclipse does work now with GWT Development Mode with Jetty , after integrating MatDes-jQuery-Lib, but when I open the address at the local host http://127.0.0.1:8888/Addressbook.html I am just getting an white browser window without content and even can not open the Dev-Tools.因此,在集成 MatDes-jQuery-Lib 之后,在Eclipse中运行和编译它现在可以使用GWT Development Mode with Jetty ,但是当我在本地主机http://127.0.0.1:8888/Addressbook.html打开地址时,我是只是得到一个没有内容的白色浏览器窗口,甚至无法打开 Dev-Tools。 Am I missing something in the configuration or is the code just not correct and I have to adjust it?我是否遗漏了配置中的某些内容,或者代码是否不正确,我必须对其进行调整?

gwt.xml gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.2//EN"
  "http://gwtproject.org/doctype/2.8.2/gwt-module.dtd">
<module rename-to='addressbook'>
  <inherits name='com.google.gwt.user.User'/>
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <inherits name='gwt.material.design.jquery.JQuery'/>
  <inherits name='gwt.material.design.GwtMaterialDesignBasic'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>
  <entry-point class='addressbook.client.Addressbook2'/>
  <!-- allow Super Dev Mode -->
  <add-linker name="xsiframe"/>
  <set-configuration-property name="CssResource.enableGss" value="true" />
  <extend-property name="locale" values="de, en"/>
  <set-property-fallback name="locale" value="en"/>
</module>

EntryPoint-Class入口点类

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootLayoutPanel;

import addressbook.client._2view.MainViewUIB;
public class Addressbook2 implements EntryPoint {

    @Override
    public void onModuleLoad() {
        Window.alert("Hello, World!");
        RootLayoutPanel.get().add(new MainViewUIB());
    }
}

MainViewUIB-Class MainViewUIB 类

package addressbook.client._2view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

import gwt.material.design.client.resources.MaterialResources;

public class MainViewUIB extends Composite {

    private static final MainViewUIBUiBinder uiBinder = GWT.create(MainViewUIBUiBinder.class);

    interface MainViewUIBUiBinder extends UiBinder<Widget, MainViewUIB> {
    }

    public MainViewUIB() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    @UiField(provided = true)
    MaterialResources res;
}

MainViewUI.ui.xml MainViewUI.ui.xml

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:m="urn:import:gwt.material.design.client.ui">
    <ui:with type="gwt.material.design.client.resources.MaterialResources" field="res"></ui:with>
    <m:MaterialPanel>
        <m:MaterialIcon marginTop="120" iconType="POLYMER" iconSize="LARGE"/>
        <m:MaterialLabel text="Hello MD World" fontSize="2em"/>
        <m:MaterialLabel text="Start building now your gwt-material apps." fontSize="0.8em"/>
    </m:MaterialPanel>
</ui:UiBinder>

That is the result I am getting by inspecting the page in chrome I just get one Element on the page:这是我通过检查 chrome 中的页面得到的结果,我只在页面上得到一个元素:

<iframe id="addressbook" tabindex="-1" style="position: absolute; width: 0px; height: 0px; border: none; left: -1000px; top: -1000px;">
<script src="http://127.0.0.1:9876/addressbook/0A7EA82001E95E9BED1D0ABA0EF89DEF.cache.js"></script>
</iframe>
@UiField(provided = true)
MaterialResources res;

The provided=true means that the.ui.xml doesn't need to create this resource, because you will provide it before calling createAndBind. provided=true意味着 the.ui.xml 不需要创建这个资源,因为你会在调用 createAndBind 之前提供它。 Failing to do this may cause NullPointerExceptions to happen while trying to make the widget, which would result in no content being visible on this path.如果不这样做可能会导致在尝试制作小部件时发生 NullPointerExceptions,这将导致此路径上没有内容可见。 However, nothing in your.ui.xml actually seems to use res (except for being declared in the ui:with , which is like declaring it as a variable), so you can probably remove both the field and the ui:with pointing at it.但是,your.ui.xml 中的任何内容似乎实际上都没有使用res (除了在ui:with中声明,这就像将其声明为变量),因此您可以同时删除该字段和ui:with指向它。

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

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