Intellij IDEA无法识别XJC任务属性 [英] Intellij IDEA doesn't recognized XJC task attributes

查看:321
本文介绍了Intellij IDEA无法识别XJC任务属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有XJC任务定义的ant build.xml文件:

 < taskdef name =xjcclassname = com.sun.tools.xjc.XJCTask > 
< classpath>
< fileset dir =jaxbincludes =*。jar/>
< / classpath>
< / taskdef>

jaxb dir cotnains jaxb-xjc.jar里面有XJCTask类。



然后我在某个目标中调用xjc任务:

 < target name =mytarget> 
< xjc target =srcpackage =com.p1.Personheader =false>
< schema dir =src / com / p1includes =Person.xsd/>
< / xjc>
< / target>

Intellij IDEA无法识别xjc调用的结构/架构并突出显示所有属性(目标,包,头文件)并包含红色的元素(模式)。



如果我选择Ant选项并将jaxb-xjc.jar添加到其他类路径列表中,这将无济于事。
我使用捆绑的Ant 1.8.2



坏的是,当我在IDEA中编译它时,我得到了很多相关的错误,但是当我运行build时脚本一切正常。我想抑制这些错误。



任何想法?

解决方案

答案来自IDEA问题跟踪器中相关错误中的此评论。
http://youtrack.jetbrains.net/issue/IDEA -11248#comment = 27-57354



对于IDEA的XJCTask问题,只需在taskdef中使用XJC2Task。



如果查看XJC2Task的源代码,它会暴露出setter,以便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



然而,XJCTask只是一个动态委托给JAXB1或JAXB2的类,因此IDEA无法解析这些属性,因为您在taskdef中定义的类没有setter。
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。



以下是一些更好的源链接:



JAXB中的XJCTask 1
http://java.net/projects/jaxb/sources/version1/content/trunk/jaxb-ri/xjc/src/com/ sun / tools / xjc / XJCTask.java?rev = 197



JAXB2中的XJCTask
http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/facade/com/sun/tools/xjc/XJCTask.java?rev=3863



JAXB2中的XJC2Task
http://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 /的包



这是从如果运行ant任务并将版本设置为1.0,则JJB2中的XJCTask。
我预计它会被允许在当天更容易从v1转换到v2。



如果你使用的是v2,则会调用XJC2Task。 / p>

实际上你不会将它设置为1.0,所以你可以直接调用XJC2Task。


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 dir cotnains jaxb-xjc.jar with XJCTask class inside.

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 doesn't recognize the structure/schema of the xjc call and highlights all attributes (target, package, header) and containing elements (schema) in red.

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

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.

Any ideas?

解决方案

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

For the XJCTask issues with IDEA, just use XJC2Task in your taskdef.

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

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

Edit: 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:

XJCTask in JAXB 1 http://java.net/projects/jaxb/sources/version1/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJCTask.java?rev=197

XJCTask in JAXB2 http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/facade/com/sun/tools/xjc/XJCTask.java?rev=3863

XJC2Task in JAXB2 http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJC2Task.java?rev=3863

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/"

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.

XJC2Task is what is called if you are using v2.

Realistically you aren't going to set it to 1.0 so you might as just call the XJC2Task directly.

这篇关于Intellij IDEA无法识别XJC任务属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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