zip construction in folder using maven assembly - pom.xml

I'm able to construct a zip, happy. But when I unzip, the content is not packed in one folder(my file name). I saw many questions and followed, all are similar but nothing cleared this. Can anyone help me in this making zip.
Thanks in advance.......
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>${maven.compile.target}</target>
<source>${maven.compile.source}</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<configuration>
<includePom>true</includePom>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<filtering>false</filtering>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<target>
<property name="version" value="${maven.version}" />
<property name="timestamp" value="${timestamp}" />
<property name="revision" value="${buildNumber}" />
<property name="basedir" value="${maven.basedir}" />
<property name="targetdir" value="${project.build.directory}" />
<property name="workbench.jar" value="${project.artifactId}-${project.version}.${project.packaging}" />
<!-- build timestamp -->
<echo file="${targetdir}/generated-resources/META-INF/build-timestamp.txt">Version: ${project.version} / Revision: ${revision} / Build: ${timestamp}</echo>
<!-- start scripts -->
<mkdir dir="${targetdir}/start" />
<copy todir="${targetdir}/start" overwrite="true">
<fileset dir="${basedir}/src/main/start" />
</copy>
<replace dir="${targetdir}/start">
<replacefilter token="#workbench.jar#" value="${workbench.jar}" />
<replacefilter token="#version#" value="Version: ${project.version} / Revision: ${revision} / Build: ${timestamp}" />
<replacefilter token="#versionnumber#" value="${project.version}" />
</replace>
<chmod dir="${targetdir}/start" perm="+x" includes="**/*.sh" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<workspace>.</workspace>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<mainClass>org.apache.chemistry.opencmis.workbench.Workbench</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix />
</manifest>
<manifestEntries>
<X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>pack-workbench</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<attach>true</attach>
<descriptors>
<descriptor>src/main/assembly/workbench-assembly.xml</descriptor>
<descriptor>src/main/assembly/workbench-ri-assembly.xml</descriptor>
<descriptor>src/main/assembly/workbench-cxf-assembly.xml</descriptor>
<descriptor>src/main/assembly/workbench-axis2-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>mac-workbench</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<attach>true</attach>
<finalName>CMIS Workbench ${project.version}.app</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>
src/main/assembly/workbench-mac-assembly.xml
</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>jnlp-inline</goal>
</goals>
</execution>
</executions>
<configuration>
<libPath>lib</libPath>
<jnlp>
<mainClass>org.apache.chemistry.opencmis.workbench.Workbench</mainClass>
</jnlp>
<pack200>true</pack200>
<gzip>true</gzip>
<sign>
<keystore>${project.build.directory}/keystore</keystore>
<keypass>password</keypass>
<storepass>password</storepass>
<alias>webstart</alias>
<validity>365</validity>
<dnameCn>OpenCMIS Development Team</dnameCn>
<dnameOu>Apache Chemistry OpenCMIS</dnameOu>
<dnameO>The Apache Software Foundation</dnameO>
<verify>true</verify>
<keystoreConfig>
<delete>true</delete>
<gen>true</gen>
</keystoreConfig>
</sign>
</configuration>
</plugin>
</plugins>
</build>

It is a bit mistake in xml file under assemblies directory. Where we need to set "true" for baseIncludeDirectory tag....

Related

How do I copy third-party jars to my target jar using Maven 3.6.0

I am trying to create a executable jar with Maven where all the third-party dependency jars are in the root. Included are two pics for examples, and my pom.xml
With this pom, I am getting this result just below it where the jars are broken out into folders.
<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:// /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.xmlrpc</groupId>
<artifactId>gz-xmlrpc-server</artifactId>
<version>1.1.0-RELEASE</version>
<packaging>jar</packaging>
<name>gz-xmlrpc-server</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.7</java-version>
<target-java-version>1.7</target-java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-junit3 -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit3</artifactId>
<version>3.0.0-M3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-server -->
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<!-- mycompany -->
<dependency>
<groupId>com.mycompany.batch</groupId>
<artifactId>gz-batch-comptroller</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${java-version}</source>
<target>${target-java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
</manifest>
<manifestEntries>
<Built-By>Michael Davidson</Built-By>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
<Class-Path>.</Class-Path>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.xmlrpc.server.Server</mainClass>
</manifest>
<manifestEntries>
<Class-Path>. gz-batch-comptroller-1.0.0-RELEASE.jar</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is what I need with the full jars included.
I see other threads on this subject, and I believe my pom is correct. But, I can't seem to get there.
Thanks.
I am not sure why you are using all the 3 maven plugins - jar, shade and assembly.
Could you try using either shade or assembly plugin. You could also refer (if not already) following link to check these plugin usages:
Difference between maven plugins ( assembly-plugins , jar-plugins , shaded-plugins)
Please remove maven-assembly-plugin and maven-jar-plugin completely from pom.xml file and then just use maven-shade-plugin as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then run mvn clean package and check generated JAR file.

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>

How to use custom *.ISS with javafx-ant, maven and INNO?

I am attempting to create a custom installer for my application using maven, inno and javafx-ant. I have looked at this link, but I do not seem to get the results described Inno and Maven
I have my installer successfully being created, and my application successfully installing. However it always goes to user/AppData/Local/. I have changed that in my custom *.iss file as follows:
DefaultDirName={pf}\cashreceipts
UsePreviousAppDir=No
Uninstallable=yes
However this file is not being picked up during the build. I have added the needed application-name.iss file at src/main/deploy/package/windows/application-name.iss however it's not picking up.
I am not sure what else to try to get this file used in my build.
Thanks!
The following is the maven configuration for the build step.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<!-- define the deploy ANT task -->
<taskdef name="jfxdeploy"
classname="com.sun.javafx.tools.ant.DeployFXTask"
classpathref="maven.plugin.classpath" />
<!-- define the JarSing ANT task -->
<!-- taskdef name="jfxsignjar"
classname="com.sun.javafx.tools.ant.FXSignJarTask"
classpathref="maven.plugin.classpath" / -->
<jfxdeploy outdir="${project.build.directory}/deploy"
outfile="${project.build.finalName}" nativeBundles="all"
verbose="true">
<info title="${project.name}" />
<!-- set the main class of your applcation -->
<application name="${project.name}"
mainClass="com.mycompany.myclass" />
<resources>
<fileset dir="${project.build.directory}"
includes="*.jar" />
<fileset dir="${project.build.directory}/dependency"
includes="*.jar" />
<fileset dir="${project.build.directory}"
includes="properties/*.properties"/>
</resources>
<!-- set your jvm args -->
<platform>
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx1024m" />
</platform>
</jfxdeploy>
<!-- you need to generate a key yourself -->
<!--jfxsignjar destdir="${project.build.directory}/deploy"
keyStore="path/to/your/keystore" storePass="yourPass"
alias="yourAlias" keyPass="keyPass">
<fileset dir="${project.build.directory}/deploy"
includes="*.jar" /> </jfxsignjar -->
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ant-javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
<finalName>cashreceipts</finalName>
</build>
I was able to confirm that ZENJAVA plug in is still being worked on and is supported at github and it can accomplish this. The information is here:
JavaFX 8 - How to build EXE with Maven & INNO
My updated pom.xml looks like this:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>myapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<url>http://www.mycompany.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javafx.version>8.0</javafx.version>
</properties>
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/lib/repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<!-- new SNAPSHOT version needed to work with current JavaFX Version -->
<id>com.zenjava</id>
<url>file://C:\Users\username\Desktop\maven fx plugin\javafx-maven-plugin-master\javafx-maven-plugin-master\target</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<!-- copy all dependencies of your app to target folder -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>com.mycompany.app.MyApp</Main-Class>
<implementation-version>1.0</implementation-version>
<JavaFX-Application-Class>com.mycompany.app.MyApp</JavaFX-Application-Class>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- copy the properties files to the root location -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources-1</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/additionalResources/properties</outputDirectory>
<resources>
<resource>
<directory>properties</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.3-SNAPSHOT</version>
<configuration>
<mainClass>com.mycompany.app.MyApp</mainClass>
<verbose>true</verbose>
<bundler>EXE</bundler>
<additionalAppResources>${project.build.directory}/additionalResources</additionalAppResources>
</configuration>
<executions>
<!-- required before build-native -->
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
<execution>
<id>create-native</id>
<phase>package</phase>
<goals>
<goal>build-native</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>myapp</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.9</version>
</dependency>
<dependency>
<groupId>customjar</groupId>
<artifactId>mycustomjar</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<organization>
<name>My Company</name>
<url>www.mycompany.com</url>
</organization>

To call specific ant target in Maven

Please find the below code snippet:-
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target name="test2">
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
</target>
<target name="test1">
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
and when i exceute "mvn compile", output of last target i.e. test1 comes. I have tried mvn compile -Dtarget="test2" and mvn compile -DantTarget="test2" but not able to call target "test2". Please help
The maven ant-run plugin only supports a single target in its configuration, but you can get the same effect by using maven profiles. Add the following to you pom.xml
<profiles>
<profile>
<id>test1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile-test1</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="test1">
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>test2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile-test2</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="test2">
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can the invoke maven as mvn -Ptest1 or mvn -Ptest2 to activate one of the profiles and execute the chosen ant target.

maven - jibx codegen - storing binding.xml

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

Resources