如何在GWT中使用JsInterop

时间:2017-10-06 14:15:42

标签: java gwt

我正在玩Gwt,想尝试JsInterop。

我定义了一个用@JsType注释的简单POJO。 Idea会在项目中看到注释类型,但构建失败时会出现注释类未定义的错误。

GWT版本2.8.1。 GWT maven插件是gwt-maven-plugin 1.0-rc-8。

编译器选项包括:

  <compilerArgs>
     <compileArg>-XjsInteropMode</compileArg>
     <compileArg>-generateJsInteropExports</compileArg>
     <compileArg>JS</compileArg>
  </compilerArgs> 


[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/egnyte/demo/gwt/StockWatcherSample-master/src/main/java/de/google/gwt/stockwatcher/client/sub/Mesage.java:[5,37] package com.google.gwt.core.client.js does not exist
[ERROR] /home/egnyte/demo/gwt/StockWatcherSample-master/src/main/java/de/google/gwt/stockwatcher/client/sub/Mesage.java:[7,2] cannot find symbol
  symbol: class JsType
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.119 s
[INFO] Finished at: 2017-10-06T16:09:52+02:00
[INFO] Final Memory: 21M/258M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project stockwatcher: Compilation failure: Compilation failure:
[ERROR] /home/egnyte/demo/gwt/StockWatcherSample-master/src/main/java/de/google/gwt/stockwatcher/client/sub/Mesage.java:[5,37] package com.google.gwt.core.client.js does not exist
[ERROR] /home/egnyte/demo/gwt/StockWatcherSample-master/src/main/java/de/google/gwt/stockwatcher/client/sub/Mesage.java:[7,2] cannot find symbol
[ERROR] symbol: class JsType

1 个答案:

答案 0 :(得分:1)

您的@JsType导入错误。它应该是

import jsinterop.annotations.JsType;

如果这不起作用,请确保您的依赖项中确实包含jsinterop-annotations版本1.0.1。

如果您看到旧的注释,那么除了GWT 2.8之外,您还在使用GWT 2.7或更早版本 - 混合版本永远不是一个好主意。