Tag: jaxb2 basics

以编程方式将WsImport与没有Maven或ANT的JAXB插件一起使用?

我正在使用WsImport从远程WSDL文件生成一些Java源代码。 请注意,这是来自常规Scala项目,即它不是在Maven或Ant构建中完成的: import com.sun.tools.ws.WsImport def run(wsdlFile: File, destination: File, packageName: String = “generated”): Seq[File] = { sys.props(“javax.xml.accessExternalDTD”) = “all” sys.props(“javax.xml.accessExternalSchema”) = “all” val xjcArgs = “” //TODO val args = s”-Xnocompile -XadditionalHeaders $xjcArgs -J-Djavax.xml.accessExternalDTD=all -b http://www.w3.org/2001/XMLSchema.xsd -p $packageName -s $destination $wsdlFile” WsImport.doMain(args.split(‘ ‘)) } 上面的代码非常有用,我用它来从Scala代码上以编程方式生成Java WSDL客户端。 但是,现在,我还想使用一些WsImport插件(例如this和this ): val xjcArgs = “-B-Xequals -B-XhashCode -B-Xvalue-constructor” 我收到此错误: […]

使用注释插件+ JAXB在x’字段’中插入自定义注释(在xsd – > java上)

使用案例: 想要将自定义注释插入到JAXB生成的java类中的字段中 问题: 使用Annotate插件+ JAXB [1],我能够成功插入自定义注释,但它们是在getter方法而不是字段中插入的。 然而,Morphia(mongo DB)注释(我实际上想要插入)只能注释java字段[2]。 我的测试xsd: 我的测试绑定xjb: 我生成的java片段: @XmlElement(required = true) protected String bar; @XmlElement(required = true) protected String hoobar; /** * Gets the value of the bar property. * * @return * possible object is * {@link String } * */ @SuppressWarnings({ }) public String getBar() { return bar; } 如你所见,我想注释“bar”字段。 […]

在Java中生成JAXB类时添加toString,hashCode,equals

我正在尝试使用Java以编程方式从XSD文件生成JAXB类。 我使用以下代码片段来实现: …. import java.io.File; import java.io.IOException; import org.xml.sax.InputSource; import com.sun.codemodel.JCodeModel; import com.sun.tools.xjc.api.S2JJAXBModel; import com.sun.tools.xjc.api.SchemaCompiler; import com.sun.tools.xjc.api.XJC; …. …. public static void generateJaxb(String schemaPath, String outputDirectory, String packageName) throws DataLoadingException { try { // Setup schema compiler SchemaCompiler sc = XJC.createSchemaCompiler(); sc.forcePackageName(packageName); // Setup SAX InputSource File schemaFile = new File(schemaPath); InputSource is = new […]

使用Mojo Jaxb2 maven插件创建Java类时生成hashCode()和equals()

我正在使用的代码是使用jaxb2-maven-plugin从XSD架构生成Java类。 我正在寻找一种方法来自动为这些类实现equals()和hashCode()方法,但似乎没有办法。 我知道还有其他JAXB2 Maven插件可以做到这一点(例如http://confluence.highsource.org/display/J2B/Home),但我想知道你们之前是否有人遇到过这个问题,如果有办法的话修理它。 我正在使用xjc目标生成类。