I generate types in a WSDL using xjc maven plugin. Following my configuration :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>auth-service-type-generation</id>
<goals>
<goal>xjc</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<encoding>UTF8</encoding>
<schemaDirectory>${wsdl.location}</schemaDirectory>
<schemaFiles>${wsdl.auth.srv.file.name}</schemaFiles>
<xmlschema>false</xmlschema>
<wsdl>true</wsdl>
<nv>false</nv>
<bindingDirectory>${project.basedir}/src/main/resources/jaxb/</bindingDirectory>
<bindingFiles>jaxb_bindings.xjb</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>
Content of jaxb_bindings.xjb :
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
I used this binding to get rid of JAXBElement but it is still generated. What's wrong in my settings or is there another way to generate types in my WSDLs without JAXBElement ?
It looks like there is missing properties in your config: schemaLocation and node.
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings schemaLocation="../path/your.xsd" node="/xs:schema">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
Related
I am working on an app using Gradle kotlin dsl, ie build.gradle is in Kotlin. I have a WSDL file that imports multiple XSDs. while compiling, Java classes are getting generated in the default location(which is mentioned in the XSDs). My requirement is that Java classes of each XSD should be generated in the custom location.
I am referring an another maven project for this. The following plugin is used to achieve my requirement.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.5</version>
<executions>
<execution>
<id>generate-sources-sample</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl_file_name.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:namespace:of:xsd:one=com.first.xsd.from.wsdl</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:namespace:of:xsd:one=com.second.xsd.from.wsdl</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried using wsdl2Java task to assign a custom location. I could not use the task as it needs CXF. It may lead to jar conflicts in my application.
extra["cxfVersion"] = "3.1.5"
project.wsdl2javaExt {
cxfVersion = "${property("cxfVersion")}"
}
tasks.getByName<no.nils.wsdl2java.Wsdl2JavaTask>("wsdl2java") {
wsdlDir = file("$projectDir/src/main/resources/xsd/trip") // wslds location
generatedWsdlDir = file("$projectDir/src/main/generated-sources/xjc/newpackage") // store generates java classes to
wsdlsToGenerate = arrayListOf(
arrayListOf("$wsdlDir/wsdl_file_name.wsdl"),
arrayListOf("-xjc", "-autoNameResolution",
"$wsdlDir/wsdl_file_name.wsdl")
)
}
Please guide me to get the same behavior in Gradle.
I have resolved it by adding the custom location in binding.xjb file in my application. The following changes worked for me.
<jaxb:bindings xmlns:tns="urn:namespace:of:xsd:one" scd="x-schema::tns">
<jaxb:schemaBindings>
<jaxb:package name="com.first.xsd.from.wsdl"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings xmlns:tns="urn:namespace:of:xsd:two" scd="x-schema::tns">
<jaxb:schemaBindings>
<jaxb:package name="com.second.xsd.from.wsdl"/>
</jaxb:schemaBindings>
</jaxb:bindings>
I am using JAXB to generate classes from my XSD file. I would like to have the classes that are generated implement a common interface. So I am trying out the JAXB2 Basics plugin with the external binding file approach to do this. This is my custom binding file:
customBindingFile.xjb
<?xml version="1.0"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="abc-api.xsd">
<jxb:bindings node="//xs:complexType[#name='MyClass']">
<inheritance:implements>com.kuldeep.CommonInterface</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Following is my maven plugin in pom file for source generation:
Note the comment added by me is the change I made to this existing plugin entry.
pom.xml
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.plugin.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- **extensions and args added by me** -->
<extensions>
<extension>org.jvnet.jaxb2_commons:jaxb2-basics:0.9.2</extension>
</extensions>
<args>
<arg>-Xinheritance</arg>
</args>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<defaultOptions>
<bindingFiles>
<bindingFile>src/main/resources/jaxws_binding.xml</bindingFile>
<bindingFile>src/main/resources/jaxb_binding.xml</bindingFile>
</bindingFiles>
</defaultOptions>
<wsdlOptions>
......
<wsdlOption>
<wsdl>${project.build.directory}/generated/framework/cxf/abc-api-inline.wsdl</wsdl>
<!-- **bindingFile added by me** -->
<bindingFile>src/main/resources/customBindingFile.xjb</bindingFile>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<!-- **dependency added by me** -->
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.2</version>
</dependency>
</dependencies>
</plugin>
The issue that I have is my schema file abc-api.xsd resides in some other project, so when I try to do maven install to generate my classes, I get error saying abc-api.xsd is not a part of this compilation.
[ERROR] Failed to execute goal
org.apache.cxf:cxf-codegen-plugin:3.0.3:wsdl2java (generate-sources)
on project : Execution generate-sources of goal
org.apache.cxf:cxf-codegen-plugin:3.0.3:wsdl2java failed:
file:/I:/project/src/main/resources/customBindingFile.xjb [9,56]:
"file:/I:/project/src/main/resources/abc-api.xsd" is not a part of
this compilation. Is this a mistake for
"file:/I:/project/src/main/resources/jaxb_binding.xml"? -> [Help 1]
And if I remove the schemaLocation attribute from customBindingFile.xjb it does not work and gives error:
XPath evaluation of "//xs:complexType[#name='MyClass']" results in
empty target node
So my question is how can I avoid providing the specific schema file name/location in customBindingFile.xjb and just have it applied to whatever xsd it's using to generate the classes.
With help from our Architect, I was able to resolve this issue. I added a jaxws binding file and used prefix-less xpath query in there to match my request elements.
This way I don't need to provide schema location anywhere and it will be applied to the specific WSDL based on the XPath query.
jaxws_binding_inheritance.xml
<jaxws:bindings version="2.0" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" jaxb:extensionBindingPrefixes="inheritance xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
<jaxws:bindings
node="*[local-name()='definitions']/*[local-name()='types']/*[local-name()='schema' and
(#targetNamespace='urn:net:mycompany:api:abc')]">
<jaxb:bindings
node="//*[local-name()='element' and
not(#name = 'ExcludeThisRequest' or #name = 'AlsoExcludeThisRequest') and
(substring(#name, string-length(#name) - string-length('Request') +1) = 'Request')]/*[local-name()='complexType']">
<inheritance:implements>com.kuldeep.CommonRequest</inheritance:implements>
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>
And added that jaxws binding file (jaxws_binding_inheritance.xml) under wsdloption for the wsdl where I wanted to apply that.
pom.xml
<wsdlOption>
<wsdl>${project.build.directory}/generated/framework/cxf/abc-api-inline.wsdl</wsdl>
<bindingFiles>
<bindingFile>src/main/resources/jaxws_binding_inheritance.xml</bindingFile>
</bindingFiles>
</wsdlOption>
I have next pom.xml:
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>test-databse-backup</id>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/db</url>
<username>usr</username>
<password>pswd</password>
<outputChangeLogFile>src/main/resources/db.changelog-databasestructure.xml</outputChangeLogFile>
</configuration>
<goals>
<goal>generateChangeLog</goal>
</goals>
</execution>
...................
So I make database backup by this maven plugin but in result file (db.changelog-databasestructure.xml) I don't see <databaseChangeLog> tag. How to fix this issue?
Thanks in advance.
I think your file src/main/resources/db.changelog-databasestructure.xml shouldn't already exist, So the plugin will create it and insert the databaseChangeLog XML element.
Otherwise, if you would keep your file exist before running the plugin, you have to insert it manually in your XML file.
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
</databaseChangeLog>
Maybe this is a bug.
I'm using the cxf-codegen-plugin to generate Java classes from wsdl files. I want to add annotations to once of the classes and I specify a Binding File and use the jaxb2-basics-annotate plugin to do so. The generated files don't contain the the annotation specified in the binding file.
Here is the configuration in the pom file
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/QueryJobService.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/QueryJobService.wsdl</wsdlLocation>
<extraargs>
<extraarg>-xjc-Xannotate</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>src/main/resources/wsdl/xsd/job-bindings.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
and here is the binding file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='resource']">
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlSeeAlso" value="model.common.sm.dcp.com.data._1.SimOrder"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
running maven in debug mode doesn't show anything strange. Is it so that cxf-codegen-plugin and jaxb2-basics-annotate don't work together ? Or is there something wrong with my configurations ?
It should work with CXF.
Please make sure that bindings are applied at all. Try to replace annox:annotate with something like <jaxb:class name="FooBar"/> - does it get generated as FooBar?
Also try the new Java Syntax: https://github.com/highsource/jaxb2-annotate-plugin instead of XML.
Finally, I guess you might be missing this attribute on your root jaxb:bindings element:
jaxb:extensionBindingPrefixes="annox"
See this example.
If nothing helps, send me a PR on github.
SO disclaimer: I'm the author of jaxb2-annotate-plugin.
I have 2 modules both having there respective pom.xmls,I would like to run pom.xml of module1 and using that run some code of module2 by using the classname to be run in the testng.xml.
Now this never works and i get a ClassNotFoundException.
Kindly help.
Cannot find class in classpath: com.org.Console1
at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:516)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1322)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:299)
at org.testng.TestNG.run(TestNG.java:972)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:88)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:104)
This is my testng.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><suite allow-return-values="false" configfailurepolicy="skip" data-provider-thread-count="10" group-by-instances="false" junit="false" name="Suite" parallel="false" preserve-order="true" skipfailedinvocationcounts="false" thread-count="5">
<test allow-return-values="false" group-by-instances="false" junit="false" name="Test" preserve-order="true" skipfailedinvocationcounts="false">
<classes>
<class name="com.org.Console1">
</class>
</classes>
</test> <!-- Test -->
This is my pom.xml
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.8</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
You don't need to specify a suite for just testing. The surefire-plugin has to be configured to catch all your java-classes, the default is to look up for "*Test.java", i personally dont like this behaviour.
pom-snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*.java</include><!-- dont just run *Test.java-files, which is default for surefire -->
</includes>
</configuration>
</plugin>
Please also verify that your test-classes are in the right position:
src/main/test/com/org/Console1.java
It HAS to be there, unless you want to configure it (which i dont recommend)