JAXB2 Basic Annotate plugin not working with maven cxf-codegen-plugin - maven

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.

Related

Modify package names of generated java classes for wsdl and xsd in gradle application

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>

JAXB2 Basics Plugins - Issue with schemaLocation in my External binding customization file

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>

liquibase doesn't insert <databaseChangeLog>

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.

JAXBElement generated even with generateElementProperty to false

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>

Javascript and CSS files combining in Maven build WITHOUT compression, minification etc

Is there an Maven plugin that just combines js and css resources but doesn't do any minification, obsucation, compressing etc? Just simple resources concatenation.
Make the following changes to your project:
In your pom.xml, <dependencies> tag, place:
<!-- JAVASCRIPT COMBINATION -->
<dependency>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-core</artifactId>
</dependency>
In your pom.xml, <plugins> tag, place:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<targetGroups>allDev</targetGroups>
<destinationFolder>${basedir}/src/main/webapp/</destinationFolder>
<contextFolder>${basedir}/src/main/webapp/</contextFolder>
</configuration>
</plugin>
In your pom.xml (or the parent pom.xml) <dependencyManagement> tag, place:
<!-- JAVASCRIPT COMBINATION -->
<dependency>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-core</artifactId>
<version>1.8.0</version>
</dependency>
Create a wro.xml under /project/src/main/webapp/WEB-INF and place something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="http://www.isdc.ro/wro">
<group name="allDev">
<js minimize="false">/my1stJsFolder/*.js</js>
<js minimize="false">/my2ndJsFolder/*.js</js>
<js minimize="false">/someFileDirectlyUnderWEBINF.js</js>
</group>
</groups>
In web.xml insert:
<filter>
<filter-name>WebResourceOptimizer</filter-name>
<filter-class>ro.isdc.wro.http.WroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>WebResourceOptimizer</filter-name>
<url-pattern>/wro/*</url-pattern>
</filter-mapping>
allDev.js will be generated under /project/src/main/webapp.
I am not sure yet how I could tell wro4j to only generate one in target (now you have two - one in the project source files and one in target).
When compressing with yui plugin I only get one in target. But this should not be that big of a problem for you.
For more:
https://code.google.com/p/wro4j/wiki/GettingStarted
https://code.google.com/p/wro4j/wiki/MavenPlugin
http://www.jarvana.com/jarvana/search?search_type=project&project=wro4j-maven-plugin
ADDITIONALLY:
If you have any problems with the resource processing try adding to <build> tag:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
And also to <plugins> add
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>swf</nonFilteredFileExtension>
<nonFilteredFileExtension>jpg</nonFilteredFileExtension>
<nonFilteredFileExtension>jpeg</nonFilteredFileExtension>
<nonFilteredFileExtension>class</nonFilteredFileExtension>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
<nonFilteredFileExtension>exe</nonFilteredFileExtension>
<nonFilteredFileExtension>wmv</nonFilteredFileExtension>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
<nonFilteredFileExtension>gz</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
I think most tools will allow you to turn off the minification.
Here is another couple that look interesting:
http://jawr.java.net/
https://code.google.com/p/wro4j/
Looks about right :
http://hammerfest.sourceforge.net/maven-javascript-plugin/merge-mojo.html
I've used YUI Compressor for years. Used to do it in ANT, but there is also a maven plugin as well. The following link is an example for aggregation:
http://alchim.sourceforge.net/yuicompressor-maven-plugin/ex_aggregation.html

Resources