似乎有一个插件JAXB的xjc
名为inject-listener-code
,它为生成的类添加了PropertyChangeListener
功能(此处引用,例如:http://hwellmann.blogspot.de/2010/05/java-xml-binding-with-property-change.html)
但是,根据JAXB-RI website,此插件已弃用且不再受支持。我尝试使用列出的Enhanced Property Listener Injection plugin,但我无法使其工作(见下文),我不确定它是否与当前的Java / JAXB版本兼容(以及它是否会将GPL许可的代码注入生成的那些不合适的课程。
是否有其他方法可以为生成的类添加PropertyChangeListener
支持?
我正在使用Java 8 Update 20.
尝试运行xjc
的详细信息:我尝试使用与Java 8打包的JAXB以及独立的JAXB 2.2.11和2.1.13(因为JAXB 2.2.x似乎有删除了两个插件所需的com.sun.tools.xjc.outline.Aspect
:
命令行:
xjc foobar.xsd -classpath "xalan-j/xalan.jar;proplistinjector-0.2.2.jar" -Xinject-prop-listeners -no-coll-listeners
使用JAXB 2.1.13
Exception in thread "main" javax.xml.transform.TransformerFactoryConfigurationEr ror: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
使用Xalan添加扩展类路径后:
Exception in thread "main" java.lang.NoSuchMethodError:
com.sun.tools.xjc.model.nav.NType.toType(Lcom/sun/tools/xjc/outline/Outline;Lcom/sun/tools/xjc/outline/Aspect;)Lcom/sun/codemodel/JType;
at org.no0ne.jaxbworks.proplistinjector.AbstractField$1TypeList.add(AbstractField.java:509)
at org.no0ne.jaxbworks.proplistinjector.AbstractField$1TypeList.add(AbstractField.java:521)
at org.no0ne.jaxbworks.proplistinjector.AbstractField.getType(AbstractField.java:525)
at org.no0ne.jaxbworks.proplistinjector.AbstractField.<init>(AbstractField.java:152)
at org.no0ne.jaxbworks.proplistinjector.AbstractListField.<init>(AbstractListField.java:118)
at org.no0ne.jaxbworks.proplistinjector.UntypedListField.<init>(UntypedListField.java:118)
at org.no0ne.jaxbworks.proplistinjector.UntypedListFieldRenderer.generate(UntypedListFieldRenderer.java:73)
at org.no0ne.jaxbworks.proplistinjector.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:92)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:777)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:558)
at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:261)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:169)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:288)
at com.sun.tools.xjc.Driver.run(Driver.java:384)
at com.sun.tools.xjc.Driver.run(Driver.java:221)
at com.sun.tools.xjc.Driver._main(Driver.java:144)
at com.sun.tools.xjc.Driver.access$000(Driver.java:82)
at com.sun.tools.xjc.Driver$1.run(Driver.java:103)
使用JAXB 2.2.11:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/xjc/outline/Aspect
at org.no0ne.jaxbworks.proplistinjector.AbstractField.<init>(AbstractField.java:152)
at org.no0ne.jaxbworks.proplistinjector.AbstractListField.<init>(AbstractListField.java:118)
at org.no0ne.jaxbworks.proplistinjector.UntypedListField.<init>(UntypedListField.java:118)
at org.no0ne.jaxbworks.proplistinjector.UntypedListFieldRenderer.generate(UntypedListFieldRenderer.java:73)
at org.no0ne.jaxbworks.proplistinjector.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:92)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:777)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:558)
at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:261)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:169)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:288)
at com.sun.tools.xjc.Driver.run(Driver.java:384)
at com.sun.tools.xjc.Driver.run(Driver.java:221)
at com.sun.tools.xjc.Driver._main(Driver.java:144)
at com.sun.tools.xjc.Driver.access$000(Driver.java:82)
at com.sun.tools.xjc.Driver$1.run(Driver.java:103)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.xjc.outline.Aspect
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more