maven - jibx codegen - storing binding.xml - binding

I'm using maven to build a jar containing generated code from an schema file using jibx. To do this I'm using the jibx-maven-plugin with the schema-codegen goal. I want to include the generated binding.xml file as part of the resulting maven jar. Is there any way of directing the jar creation to include the generated binding.xml
Currently using:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
<executions>
<execution>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
</executions>
</plugin>

David,
Good! While including the binding.xml file is not required, it is good practice. The new jibx-maven-plugin can use this file later when creating a new binding that is based on the original schema. There are plenty of examples in the JiBX source repository.
Since JiBX is OSGi enabled, it is also good practice to add an OSGi manifest when creating your jar file. This also simplifies including the binding.xml file. Even if you don't use OSGi, your jar will work fine. Here is what your project file should look like:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dataone.ns.service</groupId>
<artifactId>org.dataone.ns.service.types.v1</artifactId>
<version>0.0.1</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<schemaBindingDirectory>target/generated-sources</schemaBindingDirectory>
<includes>
<include>binding.xml</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>META-INF/binding.xml=${basedir}/target/generated-sources/binding.xml</Include-Resource>
<Export-Package>org.dataone.ns.service.types.v1.*;version=${project.version}</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-extras</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
Take a look at your jar file. Your classes, the binding.xml file, and OSGi manifest entries are there!
Don Corley
jibx-maven-plugin author

You can always use maven-antrun-plugin to copy your file(set) to target/classes.
Make sure that:
you attach the jibx plugin to a phase before package - best is generate-resources
you attach the antrun execution to the same or later, but again, before package - best is generate-resources or process-resources
the jibx plugin declaration precedes antrun declaration
Then you can use something like this:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${project.build.directory}/PATH/TO/binding.xml" todir="${project.build.outputDirectory}/PATH/IN/JAR/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
...

You can create your binding.xml in the target directory you want it to be placed in the jar like this:
...
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
...
<targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
When binding the code, you can use the refer to this directory with the <bindingDirectory> tag

You can do it using the add-resource goal of the build-helper-maven-plugin.
Example:
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/resources</schemaLocation>
<includeSchemas>
<includeSchema>foobar.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}/generated-sources</directory>
<includes>
<include>binding.xml</include>
</includes>
<targetPath>JiBX</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
You will find the binding.xml file in your jar at:
JiBX/binding.xml

Related

QuickFix/J ClassCastException after rebuilding with maven new quickfixj-messages-fix44 from new dictionary

I am trying to generate a new quick fix 4.4 message library for a custom dictionary that will be used by my initiator engine.
I have downloaded the quick fix repository to generate my new jar file from github, I then duplicated the quickfixj-messages-fix44 project under quickfixj-messages and created a new project quickfixj-messages-fix44-new, I also changed the quickfixj-messages-fix44-new pom to reflect the changes
e.g.
<artifactId>quickfixj-messages-fix44-new</artifactId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin-version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<maxmemory>3g</maxmemory>
<detectOfflineLinks>false</detectOfflineLinks>
<includeDependencySources>false</includeDependencySources>
<sourcepath>${project.basedir}/../../quickfixj-core/target/generated-sources/quickfix/fix44-new;${project.basedir}/../../quickfixj-core/target/generated-sources/quickfix/field</sourcepath>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Export-Package>quickfix.field;version="${project.version}";uses:=quickfix,quickfix.fix44new;version="${project.version}";uses:=quickfix,quickfix.field;version="${project.version}"</Export-Package>
<Import-Package>quickfix,quickfix.field;version="${project.version}"</Import-Package>
<Require-Capability>osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=${jdkLevel}))"</Require-Capability>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin-version}</version>
<configuration>
<classesDirectory>${project.basedir}/../../quickfixj-core/target/classes/</classesDirectory>
<includes>
<include>FIX44.new.xml</include>
<include>quickfix/field/*.class</include>
<include>quickfix/fix44new/**</include>
</includes>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>${maven-source-plugin-version}</version>
<configuration>
<includes>
<include>FIX44.new.xml</include>
<include>quickfix/fix44new/**</include>
<include>quickfix/field/**</include>
</includes>
</configuration>
</plugin>
also I changed under quickfixj-core pom
<Import-Package>
<!-- add dynamically-loaded version-specific message factories (optional)-->
quickfix.fix40;resolution:=optional,
quickfix.fix41;resolution:=optional,
quickfix.fix42;resolution:=optional,
quickfix.fix43;resolution:=optional,
quickfix.fix44;resolution:=optional,
quickfix.fix44new;resolution:=optional,
quickfix.fix50;resolution:=optional,
quickfix.fix50sp1;resolution:=optional,
quickfix.fix50sp2;resolution:=optional,
quickfix.fixt11;resolution:=optional,
<!-- add the required imports -->
quickfix,quickfix.field,*
</Import-Package>
<resource>
<directory>../quickfixj-messages/quickfixj-messages-fix44-new/src/main/resources</directory>
</resource>
<testResource>
<directory>../quickfixj-messages/quickfixj-messages-fix44-new/src/main/resources</directory>
</testResource>
and finally under quickfixj-distribution pom
<dependency>
<groupId>org.quickfixj</groupId>
<artifactId>quickfixj-messages-fix44-new</artifactId>
<version>${project.version}</version>
</dependency>
I was able to generate 2 jar files under target
quickfixj-messages-fix44-new-3.0.0-SNAPSHOT-sources.jar
quickfixj-messages-fix44-new-3.0.0-SNAPSHOT.jar
the thing is every time I received a message from acceptor engine I get exception under my MessageCracker saying:
java.lang.ClassCastException: class quickfix.Message cannot be cast to class quickfix.fix44new.Message (quickfix.Message and quickfix.fix44new.Message are in unnamed module of loader 'app')

using swagger-codegen-maven-plugin without spring-boot dependency

I have requirement to generate rest api using swagger. I have written yaml files for generating Rest API. In my pom.xml i have
Blockquote
`<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>sample-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger.yaml</inputSpec>
<output>src/test/java</output>
<language>spring</language>
<configOptions>
<sourceFolder>/</sourceFolder>
</configOptions>
<apiPackage>io.swagger.handler</apiPackage>
<modelPackage>io.swagger.model</modelPackage>
<invokerPackage>io.swagger.handler</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>`
but when i execute "mvn clean install" it asks me to provide org.springframework.boot dependency. Is there any way i can use this plugin without spring-boot dependency?
<!-- SWAGGER -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${basedir}/swagger.yaml</inputSpec>
<language>spring</language>
<output>${basedir}</output>
</configuration>
</execution>
</executions>
</plugin>

Generating findBugs report in Jenkins

I have to run the findBugs from Jenkins and generate the report to a specific file. I am looking for detailed steps to do this.
I have added the plugin in Jenkins and have the below in the pom.xml
enter code here
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<id>findbug</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<findbugsXmlOutputDirectory>
${project.build.directory}/findbugs
</findbugsXmlOutputDirectory>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/findbugs</dir>
<outputDir>${project.build.directory}/findbugs</outputDir>
<stylesheet>fancy-hist.xsl</stylesheet>
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<id>failing-on-high</id>
<phase>install</phase>
<goals>
<goal>findbugs</goal>
<goal>check</goal>
</goals>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<failOnError>true</failOnError>
</configuration>
</execution>
</executions>
</plugin>
How to run findBugs and generate report?
You need this in the findbugs-maven-plugin configuration section:
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<xmlOutput>true</xmlOutput>
Also, you need to run the maven goal findbugs:findbugs. You can find details in the "How to Use" section of the plugin description page here: https://wiki.jenkins-ci.org/display/JENKINS/FindBugs+Plugin

How to run `jacoco-maven-plugin` with `-Xbootclasspath/p:my.jar` option?

To successfully run my unit tests I have to provide JVM with some replaced standard classes. Therefore, I use following configuration for maven-surefire-plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>${skipUTs}</skipTests>
<argLine>-Xbootclasspath/p:my.jar</argLine>
</configuration>
</plugin>
plugin/configuration/argLine added, nothing special. But how can I tell jacoco the same thing? The jacoco doesn’t have configuration/argLine :( .
I have configured the Maven JaCoCo plugin as follows in my pom.xml file:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<skip>${skipUTs}</skip>
<!-- NO ONE (((((
<argLine>-Xbootclasspath/p:my.jar</argLine>
-->
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
As stated in documentation of prepare-agent - it simply sets property argLine that is used by maven-surefire-plugin, and you have two options to add additional arguments:
<properties>
<argLine>-your -extra -arguments</argLine>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- no argLine here -->
</configuration>
</plugin>
or using late property evaluation feature of maven-surefire-plugin:
<properties>
<!-- empty to avoid JVM startup error "Could not find or load main class #{argLine}" in case when jacoco-maven-plugin not executed -->
<argLine></argLine>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>#{argLine} -your -extra -arguments</argLine>
</configuration>
</plugin>

Delete old artifact version before copy dependencies

I used maven-dependency-plugin to copy the current artifact into a custom directory :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-to-dsf-server</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${tomcat.dsf.dir}/lib/pacifisc</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But when the artifact version changes I have two versions of the same jar into the destination directory. How can I delete the old version ?
Regards,
Arnaud
I finally used the maven-clean-plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>clean-dsf-server</id>
<phase>package</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<filesets>
<directory>${tomcat.dsf.dir}/lib/pacifisc</directory>
<includes>
<include>${project.artifactId}*.jar</include>
</includes>
</filesets>
</filesets>
</configuration>
</execution>
</executions>
</plugin>

Resources