Generating custom manifests with Maven and multiple specially-named classpaths - java

I'm trying to implement a Maven build process for YAJSW (Yet Another Java Service Wrapper). The part I'm currently working on is generating a custom manifest for the jar to ape the format used in the currently hard-coded MANIFEST.MF file, like so:
Manifest-Version: 1.0
Class-Path-Wrapper-Core:
./wrapperApp.jar
./lib/core/yajsw/ahessian.jar
.
.
.
./lib/core/regex/jrexx-1.1.1.jar
Class-Path-Wrapper-Extended:
./lib/extended/commons/commons-httpclient-3.0.1.jar
./lib/extended/commons/commons-codec-1.3.jar
.
.
./lib/extended/abeille/formsrt.jar
Class-Path-App:
./wrapper.jar
.
.
./lib/core/commons/commons-logging-1.1.jar
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
I've managed to produce suitably formatted classpaths using the dependency:build-dep task like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>generate-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<attach>true</attach>
<localRepoProperty>.</localRepoProperty>
<pathSeparator>$${pathDelim}</pathSeparator>
<outputFile>${basedir}/target/assembly/classPath</outputFile>
</configuration>
</execution>
</executions>
</plugin>
N.B. the $${pathDelim} part was arrived at after much experimentation with escaping, antrun and properties. Initially I tried to add newlines directly using the pathSeparator parameter. I found that the only way I could do this was to use $${line.separator}. Seems there's an extra layer of de-escaping that happens somewhere in the pipeline.
This code successfully generates a classPath file in the required format. Now I had to merge this into a MANIFEST.MF file.
On reviewing all the options, I've done this using an Antrun task :
<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>
<property name="cp.props"
value="${basedir}/target/assembly/classPath.properties" />
<concat destfile="${cp.props}">
<string>wrapper.core.classpath=</string>
<filelist dir="${basedir}/target/assembly" files="classPath" />
</concat>
<property file="${cp.props}" />
<echo file="${MANIFEST}"
message="Manifest-Version: 1.0${line.separator}Class-Path-Wrapper-Core: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Class-Path-Wrapper-Extended: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Class-Path-App: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter${line.separator}" />
<replace file="${MANIFEST}" token="${pathDelim}" value=" " />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
This produced more or less the correct output in the MANIFEST.MF file:
Manifest-Version: 1.0
Class-Path-Wrapper-Core:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Class-Path-Wrapper-Extended:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Class-Path-App:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
which I then pointed to in the jar plugin settings:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3</version>
<configuration>
<useDefaultManifestFile>false</useDefaultManifestFile>
<archive> <manifestFile>${MANIFEST}</manifestFile> </archive>
</configuration>
</plugin>
However, looking in the resultant jar, it seems to have flattened the output, like so:
Manifest-Version: 1.0 Class-Path-Wrapper-Core: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Class-Path-Wrapper-Extended: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Class-Path-App: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
Archiver-Version: Plexus Archiver
Created-By: 20.0-b11 (Sun Microsystems Inc.)
Any idea how to fix this?
P.S.On further inspection, it appears this flattening is mostly a natural consequence of the jar-building process, and happened in the original Gradle build too. However, I still have all the classpaths on one line, and need to keep them separate... I wonder if this is as a result of the merging of multiple discrete manifests by Gradle?

Looks like the indentation in the POM file was causing spaces to appear in the generated MANIFEST.MF file, and those spaces were being interpreted as indication of line continuation.
I've rejigged the antrun section as follows:
<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>
<property name="cp.props"
value="${basedir}/target/assembly/classPath.properties" />
<property name="ls" value="${line.separator}"/>
<concat destfile="${cp.props}">
<string>wrapper.core.classpath=</string>
<filelist dir="${basedir}/target/assembly" files="classPath" />
</concat>
<property file="${cp.props}" />
<echo file="${MANIFEST}"
message="Manifest-Version: 1.0
${ls}Class-Path-Wrapper-Core: ${ls} ${wrapper.core.classpath}${ls}
${ls}Class-Path-Wrapper-Extended: ${ls} ${wrapper.core.classpath}${ls}
${ls}Class-Path-App: ${ls} ${wrapper.core.classpath}${ls}
${ls}Main-Class: org.rzo.yajsw.boot.WrapperExeBooter${ls}" />
<replace file="${MANIFEST}" token="${pathDelim}" value=" " />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
YAJSW seems a bit happier now when referencing the classpaths in the .jar, although I haven't got it quite right yet. Still, pretty happy with this outcome! Hope all my findings are of use to someone - I couldn't find this info on SO or in the Maven docs.

Related

maven-antrun-plugin skips an execution

I added to my Maven project the solution advised in this Stack Overflow question. The only difference to the suggested solution that I introduced was to replace the <tasks /> with the <target /> (the issue I am experiencing appears with either).
Everything works excellent on the testing side. When I run my tests the correct (test-persistence.xml) persistence file is being used. However when I am doing clean install or even hit run from my IDE (Netbeans 8.2) only the first target (copy-test-persistence) is being executed. The second execution is being entered after the tests (see the build output below), but target is not executed. What I do get after every clean install and when running the app on the server is that the contents of the test-persistence.xml are in the persistence.xml file. The right content remains in the persistence.xml.proper created in the first target.
--- maven-antrun-plugin:1.8:run (copy-test-persistence) # RimmaNew ---
Executing tasks
main:
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
Executed tasks
...
--- maven-antrun-plugin:1.8:run (restore-persistence) # RimmaNew ---
Executing tasks
main:
Executed tasks
You will notice that 0 tasks are executed under restore-persistence. Strangely enough in the created /target/antrun folder there's a build-main.xml file which includes the skipped task:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<copy file="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml.proper" tofile="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml"/>
</target>
</project>
It would be appreciated if you could give me a hint as I can't get my head around this. As it is common I am posting my current pom.xml:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-test-persistence</id>
<phase>process-test-resources</phase>
<configuration>
<target>
<!--backup the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper" />
<!--replace the "proper" persistence.xml with the "test" version-->
<copy file="${project.build.testOutputDirectory}/META-INF/test-persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>restore-persistence</id>
<phase>prepare-package</phase>
<configuration>
<target>
<!--restore the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The issue has got to do with how Ant's copy task work:
By default, files are only copied if the source file is newer than the destination file, or when the destination file does not exist.
This is the problem here. Ant detects that the target file already exists, and that it is not newer. There is a granularity to determine "newer", and by default, it is 1 second, or 2 seconds on DOS systems. So what happens is that, during the build, the persistence.xml is copied by Maven into the build directory, its last modified date is changed (the Resources Plugin doesn't keep it), and then your own copy is just few milliseconds later. Thus, the copied persistence.xml.proper will never be newer because this all happens during the default granularity.
You can force the copy by setting the overwrite parameter to true with
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true"/>
Or you could use the move task instead, since you probably don't need to keep the .proper file anyway:
<move file="${project.build.outputDirectory}/META-INF/persistence.xml.proper"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />

Gracefully stopping a java process started by maven-antrun-plugin

This question is a result of an answer to this question from yesterday
run a java application and a web application in a single maven build within a reactor project
So as answered in the above question I now have a maven-antrun-plugin that forks a child process and runs my java appserver using a configuration like this -
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase> verify </phase>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<exec executable="java" spawn="true">
<arg value="-classpath"/>
<arg value="${runtime_classpath}"/>
<arg value="somepackage.AppServer"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The above configuration smoothly starts my appserver as a background process.
Now my question is if there is an easy way I can locate this process and stop it if I need after I start it through my build.
You can use the jps utility that is bundled inside the JDK to get the process ID of a running Java executable:
The jps tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.
Then, when we have retrieved the process ID, we can kill it using taskkill on Windows or kill or Unix system.
This would be a sample configuration of the maven-antrun-plugin. It declares the jps executable and redirect the result of its invocation in the property process.pid with the <redirector> attribute. The result is filtered with <outputfilterchain> so that only the lines corresponding to the executable AppServer are kept. jps output is in the form [PID] [NAME] so the name is then removed with <replacestring>; this way, we only keep the PID. Finally, there are two exec configuration depending on the OS.
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<exec executable="java" spawn="true">
<arg value="-classpath" />
<arg value="${runtime_classpath}" />
<arg value="somepackage.AppServer" />
</exec>
<exec executable="${JAVA_HOME}/bin/jps">
<arg value="-l" />
<redirector outputproperty="process.pid">
<outputfilterchain>
<linecontains>
<contains value="somepackage.AppServer" />
</linecontains>
<replacestring from=" somepackage.AppServer" />
</outputfilterchain>
</redirector>
</exec>
<exec executable="taskkill" osfamily="winnt">
<arg value="/PID" />
<arg value="${process.pid}" />
</exec>
<exec executable="kill" osfamily="unix">
<arg value="-15" />
<arg value="${process.pid}" />
</exec>
</target>
</configuration>
Since you mentioned "gracefully", I used the -15 option on Unix and didn't include the /F option for Windows. If you want to force the exit, you can use kill -9 on the Unix system and add the /F option on Windows.
Having tried various options, I've found that the process-exec-maven-plugin to be best. I realize that the OP is asking about maven-antrun-plugin specifically but that is because of an answer received to a generic question.
https://github.com/bazaarvoice/maven-process-plugin
An example of using it to start a nodeJs server which is used as part of integration tests:
<plugin>
<groupId>com.bazaarvoice.maven.plugins</groupId>
<artifactId>process-exec-maven-plugin</artifactId>
<version>${process-exec-maven-plugin.version}</version>
<executions>
<!-- Start process -->
<execution>
<id>node-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<name>node-server</name>
<workingDir>../../test-server-dir</workingDir>
<waitForInterrupt>false</waitForInterrupt>
<healthcheckUrl>http://localhost:3000/</healthcheckUrl>
<arguments>
<argument>node</argument>
<argument>./app.js</argument>
</arguments>
</configuration>
</execution>
<!--Stop all processes in reverse order-->
<execution>
<id>stop-all</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-all</goal>
</goals>
</execution>
</executions>
</plugin>

How can I get the Javadoc class descriptions at compile time?

I'm trying to build up some documentation for my Wicket Web Application. I have created a page to grab all of my mounted pages and display them in /sitemap.xml.
In the vein of documentation I've added a new tag to the file <siteMap:Description>
now I want to fill that description with the javadoc entry that describes the class file.
I know there is know direct way to access them at runtime. So Instead I'm hoping to copy them at compile time into a List where they will then be accessible from runtime. How would I do that?
I'm using Maven for my build.
EDIT
I should probably Also mention that I do have an AntTask Already defined as part of my build process to save the compile Dates/times to a property file.
It seems to me an Task to scan my Class and then put the information into a file is probably the way to go. Problem is I'm not sure how to proceed.
My Ant-Task is defined like in my pom.xml so:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>set-build-time</id>
<phase>process-sources</phase>
<configuration>
<tasks>
<tstamp>
<format property="build.timestamp" pattern="yyyy/MM/dd HH:mm:ss"/>
<format property="build.time" pattern="HH:mm:ss" />
<format property="build.date" pattern="MM/dd/yyyy" />
<format property="build.year" pattern="yyyy"/>
</tstamp>
<replaceregexp byline="true">
<regexp pattern="copyYear\=.*" />
<!--suppress MavenModelInspection -->
<substitution expression="copyYear=${build.year}" />
<fileset dir="src/main/java/" includes="**/*.properties" />
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="buildTime\=.*" />
<!--suppress MavenModelInspection -->
<substitution expression="buildTime=${build.date} ${build.time}" />
<fileset dir="src/main/java/" includes="**/*.properties" />
</replaceregexp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
After doing more research I determined I was barking up the wrong tree.
I since I was trying to get Javadoc comments A Doclet was the better answer.
So I implemented a custom doclet and wired it up to run automatically as described in
the follow up question and answer below.
How can I compile and run my Custom Doclet class in my project?

Sharing test resourcing between modules issue

I want to share test resources between 2 modules A and B. In A test resources I have directory with some files. Like this
-dir
----f1
----f2
I've done all according to Share test resources between maven projects . Now from B test I can access to resources using syntax like:
this.getClass().getClassLoader().getResource("dir/f1")
And it's works perfectly fine. But I don't want hardcore all file names like f1 or f2. What I really want is getting all files from directory. Like
File foo = new File(this.getClass().getClassLoader().getResource("dir").getFile());
assert foo.isDirectory()
foo.list()
...
But when I create foo in such way it even doesn't exist (foo.exist() returns false).
How can I deal with it?
Update. Alternative solution using ant
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<configuration>
<target>
<fileset id="d" dir="${basedir}/src/test/resources/dir" includes="*"/>
<pathconvert property="d" refid="d">
<map from="${basedir}/src/test/resources/" to=""/>
</pathconvert>
<touch file="${basedir}/src/test/resources/d/listOfCharts.txt"/>
<echo file="${basedir}/src/test/resources/d/listOfCharts.txt" message="${charts}"/>
</target>
</configuration>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The approach you talk about creates a JAR which can be used in later tests. You can't list the contents of a Jar this way. You need to use Jar you need to read it as a Jar specially
How do I list the files inside a JAR file?

control schema file name created by jaxb schemagen maven plugin (maven-jaxb-schemagen-plugin)

I don't seem to be able to work out how to get control the file name of the XSD file created by maven-jaxb-schemagen-plugin. The documentation is a bit sparse.
<groupId>com.sun.tools.jxc.maven2</groupId>
<artifactId>maven-jaxb-schemagen-plugin</artifactId>
<version>1.2</version>
<configuration>
<project>${project}</project>
<destdir>${project.build.directory}/generated-resources/schemas</destdir>
<srcdir>${project.build.sourceDirectory}/my/jaxb/bean/package</srcdir>
<verbose>true</verbose>
</configuration>
It always seems to create a file called schema1.xsd
You need to add schema elements which describe which file should contain the elements of each namespace you have:
<configuration>
[...]
<schemas>
<schema>
<namespace>http://www.example.invalid/2001/05/27/wibble</namespace>
<file>wibble.xsd</file>
</schema>
</schemas>
<configuration>
Assuming you have set the namespace of you components
#XmlRootElement(name = "wobble", namespace="http://www.example.invalid/2001/05/27/wibble")

Categories

Resources