如何在客户端为 GWT 使用 JAXB 注释? [英] How to use JAXB annotations in the client side for GWT?

查看:25
本文介绍了如何在客户端为 GWT 使用 JAXB 注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样在我的班级中使用 JaxB 注释:

I wanted to use the JaxB annotation in my class like this:

@XmlRootElement
public class ItemExtension implements Serializable {

但是当我把它放在客户端时 GWT 会抱怨.

But GWT complains when I put it in the client side.

 [ERROR] Line 4: The import javax.xml.bind cannot be resolved
         [ERROR] Line 14: XmlRootElement cannot be resolved to a type

是否有解决方法或我做错了什么?

Is there a workaround or am I doing something wrong?

推荐答案

我有一个项目,它在客户端 GWT 代码中使用带有 JPA 和 JAXB 注释的实体类.请参阅GWT 文档.

I have a project that uses entity classes with both JPA and JAXB annotations in the client-side GWT code. See the section "Overriding one package implementation with another" in the GWT Documentation.

假设您的模块位于 com.example.app 包中.您需要在新包中重新创建[1] 所有 JAXB 注释类,特别是 com.example.app.jre.java.xml.bind.annotation;在您的模块 XML 文件中,然后添加 <super-source path="jre"/> 并设置.

Let's say your module is in package com.example.app. You will need to recreate[1] all JAXB annotation classes in a new package, specifically com.example.app.jre.java.xml.bind.annotation; in your module XML file, you then add <super-source path="jre" /> and you're set.

请注意,您不需要分发该包中的类文件,它们只是为了 GWT 编译器而需要.

Note that you don't need to distribute the class files in that package, they are needed solely for the sake of the GWT compiler.

[1]:您可以复制它们并调整所有包引用.

[1]: You can copy them over and adjust all package references.

这篇关于如何在客户端为 GWT 使用 JAXB 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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