问题描述
我有一个带有 XJC 任务定义的 ant build.xml 文件:
I have an ant build.xml file with XJC task definition:
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<fileset dir="jaxb" includes="*.jar" />
</classpath>
</taskdef>
jaxb 目录包含 jaxb-xjc.jar,其中包含 XJCTask 类.
jaxb dir cotnains jaxb-xjc.jar with XJCTask class inside.
然后我在某个目标中调用 xjc 任务:
Then I call xjc task in some target:
<target name="mytarget">
<xjc target="src" package="com.p1.Person" header="false">
<schema dir="src/com/p1" includes="Person.xsd"/>
</xjc>
</target>
Intellij IDEA 无法识别 xjc 调用的结构/架构,并以红色突出显示所有属性(目标、包、标头)和包含元素(架构).
Intellij IDEA doesn't recognize the structure/schema of the xjc call and highlights all attributes (target, package, header) and containing elements (schema) in red.
如果我选择 Ant 选项并将 jaxb-xjc.jar 添加到其他类路径列表,这没有帮助.我使用捆绑的 Ant 1.8.2
If I choose Ant options and add jaxb-xjc.jar to additional class path list this doesn't help.I use bundled Ant 1.8.2
不好的是,当我在 IDEA 中编译它时,会出现很多相关错误,但是当我运行构建脚本时,一切正常.我想抑制这些错误.
The bad thing is that when I compile it in IDEA I get a lot of related errors, but when I run build script everything works fine. I want to suppress these errors.
有什么想法吗?
推荐答案
答案来自 IDEA 问题跟踪器中相关错误中的此评论.http://youtrack.jetbrains.net/issue/IDEA-11248#comment=27-57354
The answer comes from this comment in a related bug in the IDEA issue tracker.http://youtrack.jetbrains.net/issue/IDEA-11248#comment=27-57354
对于 IDEA 的 XJCTask 问题,只需在 taskdef 中使用 XJC2Task.
For the XJCTask issues with IDEA, just use XJC2Task in your taskdef.
如果您查看 XJC2Task 的源代码,它会公开设置器,以便 IDEA 可以解析它们:http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJC2Task.java#XJC2Task.setPackage%28java.lang.String%29
If you look at the source of XJC2Task, it has the setters exposed so that IDEA can resolve them:http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJC2Task.java#XJC2Task.setPackage%28java.lang.String%29
然而,XJCTask 只是一个动态委托给 JAXB1 或 JAXB2 的类,因此 IDEA 无法解析这些属性,因为您在 taskdef 中定义的类没有设置器.http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJCTask.java#XJCTask.getCoreClassName%28%29
However, XJCTask is just a class to dynamically delegate to JAXB1 or JAXB2 on the fly so IDEA is unable to resolve these properties since the class you are defining in the taskdef doesn't have the setters on it.http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJCTask.java#XJCTask.getCoreClassName%28%29
基本上在 JAXB2 中,XJCTask 实际上并不包含任务 - 它委托给实际任务 XJC2Task.
Basically in JAXB2, XJCTask doesn't actually contain the task - it delegates to the actual task XJC2Task.
这里有一些更好的来源链接:
Here are some better links to the source:
JAXB 1 中的 XJCTaskhttp://java.net/projects/jaxb/sources/version1/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJCTask.java?rev=197一个>
XJCTask in JAXB 1http://java.net/projects/jaxb/sources/version1/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJCTask.java?rev=197
JAXB2 中的 XJCTaskhttp://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/facade/com/sun/tools/xjc/XJCTask.java?rev=3863一个>
XJCTask in JAXB2http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/facade/com/sun/tools/xjc/XJCTask.java?rev=3863
JAXB2 中的 XJC2Taskhttp://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJC2Task.java?rev=3863一个>
XJC2Task in JAXB2http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJC2Task.java?rev=3863
如果您查看 jaxb-xjc-ri-2.x-xx.jar,您会看到它包含一个名为1/com/sun/tools/xjc/"的包
If you look at your jaxb-xjc-ri-2.x-xx.jar you will see that it contains a package called "1/com/sun/tools/xjc/"
如果您在将版本设置为 1.0 的情况下运行您的 ant 任务,这就是从 JAXB2 中的 XJCTask 调用的内容.我希望它可以在当天更轻松地从 v1 过渡到 v2.
This is what gets called from the XJCTask in JAXB2 if you run your ant task with setting the version to 1.0.I expect it was put in to allow easier transitions to v2 from v1 back in the day.
如果您使用的是 v2,则称为 XJC2Task.
XJC2Task is what is called if you are using v2.
实际上,您不会将其设置为 1.0,因此您可以直接调用 XJC2Task.
Realistically you aren't going to set it to 1.0 so you might as just call the XJC2Task directly.
这篇关于Intellij IDEA 无法识别 XJC 任务属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!