简体   繁体   English

对JAXB使用package-info.java

[英]Using package-info.java for JAXB

I am unable to build my application because of the syntax in the package-info.java file. 由于package-info.java文件中的语法,我无法构建我的应用程序。 The sample below is just a demo but any sample I try gives me the syntax errors I would expect since I'm placing code before the package and imports. 下面的示例只是一个演示,但是我尝试的任何示例都会给我带来语法错误,因为我将代码放在打包和导入之前。 How exactly are you suppose to get this to work if the syntax below is what is actually suppose to go into package-info.java? 如果以下语法实际上是应该放在package-info.java中的语法,那么您究竟想如何使它起作用?

Update: Another way to ask this question is, shouldn't the annotation go at the bottom? 更新:问这个问题的另一种方法是,注释不应该放在底部吗? My compiler, IntelliJ, certainly things so... 我的编译器IntelliJ肯定是这样...

@XmlSchema(
    elementFormDefault=XmlNsForm.QUALIFIED,
    namespace="http://www.example.com/FOO",
    xmlns={@XmlNs(prefix="bar",
                  namespaceURI="http://www.example.com/BAR")}
)
package blog.prefix;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

The problem was my IDE. 问题是我的IDE。 For this to work in IntelliJ you must disable "Optimize Imports". 为了使它在IntelliJ中起作用,您必须禁用“优化导入”。

在IntellIJ 2018版本中工作正常:)

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

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