【发布时间】:2019-07-27 00:25:08
【问题描述】:
我在我的 Java 项目中收到此错误消息。如何解决?我只是构建了 Vaadin 的标准架构类型应用程序示例。我想尝试将 JavaScript 包含到我的项目中。但是简单的注释已经给出了错误消息:@JavaScript is no annotation type
我试过这个:Project->Properties->JavaCompiler->AnnotationProcessing->Enable 还是报错。也许我必须包含某些 .jar?
代码如下:
package my.vaadin.app;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.annotations.*;
/**
* This UI is the application entry point. A UI may either represent
* a browser window
* (or tab) or some part of an HTML page where a Vaadin application
* is embedded.
* <p>
* The UI is initialized using {@link #init(VaadinRequest)}. This
* method is intended to be
* overridden to add component to the user interface and initialize
* non-component functionality.
*/
@Theme("mytheme")
@JavaScript("javascript-test.js")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
final TextField name = new TextField();
name.setCaption("Type your name here:");
Button button = new Button("Click Me");
button.addClickListener(e -> {
layout.addComponent(new Label("Thanks " + name.getValue()
+ ", it works!"));
});
layout.addComponents(name, button);
setContent(layout);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet",
asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode =
false)
public static class MyUIServlet extends VaadinServlet {
}
}
【问题讨论】:
-
您希望该注释来自哪里?注释就像类:你必须
import他们或者共享同一个包。 -
@Pointy 看起来像 Vaadin 功能,但由于 OP 未显示 minimal reproducible example,因此只能猜测缺少导入。
-
很抱歉没有显示所有内容。但我导入了 com.vaadin.annotations.*; @Pointy:顺便说一下,Eclipse 中有两个不同的错误符号。如果导入丢失,错误符号看起来会有所不同。
-
@Pointy:请您删除反对票。我认为我添加了足够的信息。
-
@cryp71x 我愿意,但我没有投反对票。
标签: javascript java eclipse annotations vaadin