我有一个名为 MYClass 的类,其代码如下
package com.rest;
public class MyClass {
private String var;
public String getVar() {
return var;
}
public void setVar(String var) {
this.var = var;
}
}
我已经使用 schemagen ../src/com/rest/MyClass.java Generated Schema 创建了它的模式:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="myClass">
<xs:sequence>
<xs:element name="var" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
然后,我使用模式创建了 JAXB 工件
xjc -d <my_source_dir>\ -p com.rest.generated <my_generated_schema>.xsd
生成的工件代码如下
对象工厂:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.06.01 at 08:56:31 PM PKT
//
package com.rest.generated;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.rest.generated package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.rest.generated
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link MyClass }
*
*/
public MyClass createMyClass() {
return new MyClass();
}
}
而 MyClass.java 是
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.06.01 at 08:56:31 PM PKT
//
package com.rest.generated;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for myClass complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="myClass">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="var" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "myClass", propOrder = {
"var"
})
public class MyClass {
protected String var;
/**
* Gets the value of the var property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getVar() {
return var;
}
/**
* Sets the value of the var property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setVar(String value) {
this.var = value;
}
}
问题:找不到创建 JAXBElement 的方法。我应该怎么做才能得到那个方法