【发布时间】:2018-03-10 21:12:15
【问题描述】:
我正在关注 GWT 文档 Coding Basics - JavaScript: JsInterop,通过注解 @JsMethod 将 Java 类导出到 JavaScript。但是,Java 类不会转译成 JavaScript。
这是我的 Java 类:
package io.mincongh.client;
import jsinterop.annotations.JsMethod;
public class ExportedMethods {
@JsMethod
public static String sayHello(String name) {
return "Hello, " + name;
}
}
我的项目是在 Maven 中构建的,通过 GWT Maven 插件 2.8.2:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>StockMarket.html</runTarget>
<modules>
<module>io.mincongh.StockMarket</module>
</modules>
</configuration>
</plugin>
当我在浏览器的控制台中调用导出的方法时。那么方法没有定义:
io.mincongh.client.ExportedMethods.sayHello('world');VM59:1 Uncaught ReferenceError: io is not defined 在:1:1
【问题讨论】:
标签: javascript java gwt gwt-jsinterop