Invoking JWS ant script with maven
Posted: Fri Jan 20, 2012 11:49 pm
I am using maven and the maven ant plugin to invoke your JWS ant shell script that eventually executes the ant build.xml When I invoke the ant shell script from a unix terminal everything works fine without any changes needed. The problems creep up only when I invoke it through maven ant plugin.
There were several things I had to do to get it to work properly. Although the changes are relatively small, they took some time to figure out. I don't know if any other users have this same use-case but perhaps by informing you how I got it to finally work with maven, it may save some other people a lot of time.
Also if you have any suggestions on a better way to do this with maven, I would appreciate it. I have documented the steps below. Note, this was done on a Mac OS X machine, so I assume this would also work on any unix/linux clone.
1. Change the oxygen/tools/jwsPackager/ant shell script
From:
export ANT_EXEC=..\ant\bin\ant
sh $ANT_EXEC $@
To:
export ANT_EXEC=target/oxygen/oxygen/tools/ant/bin/ant
sh $ANT_EXEC $@ -buildfile target/oxygen/oxygen/tools/jwsPackager/build.xml
The buildfile path is relative to where the ant shell script file resides. If I didn't do this, I would get an error stating that antbinant is not a recognized command.
2. Change the build.xml java execution
From:
<java classname="ro.sync.jws.JwsPackager">
<sysproperty
key="javax.xml.parsers.DocumentBuilderFactory"
value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
<classpath>
<pathelement path="${home}/classes"/>
<pathelement location="${home}/lib/deployer.jar"/>
<pathelement location="${home}/lib/deployerUtils.jar"/>
<pathelement location="${home}/lib/log4j.jar"/>
<pathelement location="${home}/lib/serializer.jar"/>
</classpath>
<arg value="${propertyFile}"/>
</java>
</target>
To:
<java jar="lib/rackspace-oxygen.jar" fork="true">
<sysproperty
key="javax.xml.parsers.DocumentBuilderFactory"
value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
<arg value="packager.properties"/>
</java>
rackspace-oxygen.jar is created from extracting all the classes from deployer.jar, deployerUtils.jar, serializer.jar, and log4j.jar and jar'ing them into oxygen/tools/jwsPackager/lib/rackspace-oxygen.jar
Also, I had to include a META-INF/MANIFEST.MF file inside rackspace-oxygen.jar which had the entry:
Main-Class: ro.sync.jws.JwsPackager
3. Create oxygen/tools/jwsPackager/lib/rackspace-oxygen.jar as described in the previous step.
Once I did those 3 things I was able to create the oxygenJWS.zip by invoking the ant shell script via a maven's ant plugin. It seems like once you invoke the shell script or the ant build.xml in maven, the java class path specified in the build.xml is totally ignored. I tried so many different path variations and other ant command combinations but I could never get it to work. In the end, the steps I mentioned above was the only way I could get it to work. If you have any suggestions on a better way to do this with maven, your input would be appreciated.
There were several things I had to do to get it to work properly. Although the changes are relatively small, they took some time to figure out. I don't know if any other users have this same use-case but perhaps by informing you how I got it to finally work with maven, it may save some other people a lot of time.
Also if you have any suggestions on a better way to do this with maven, I would appreciate it. I have documented the steps below. Note, this was done on a Mac OS X machine, so I assume this would also work on any unix/linux clone.
1. Change the oxygen/tools/jwsPackager/ant shell script
From:
export ANT_EXEC=..\ant\bin\ant
sh $ANT_EXEC $@
To:
export ANT_EXEC=target/oxygen/oxygen/tools/ant/bin/ant
sh $ANT_EXEC $@ -buildfile target/oxygen/oxygen/tools/jwsPackager/build.xml
The buildfile path is relative to where the ant shell script file resides. If I didn't do this, I would get an error stating that antbinant is not a recognized command.
2. Change the build.xml java execution
From:
<java classname="ro.sync.jws.JwsPackager">
<sysproperty
key="javax.xml.parsers.DocumentBuilderFactory"
value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
<classpath>
<pathelement path="${home}/classes"/>
<pathelement location="${home}/lib/deployer.jar"/>
<pathelement location="${home}/lib/deployerUtils.jar"/>
<pathelement location="${home}/lib/log4j.jar"/>
<pathelement location="${home}/lib/serializer.jar"/>
</classpath>
<arg value="${propertyFile}"/>
</java>
</target>
To:
<java jar="lib/rackspace-oxygen.jar" fork="true">
<sysproperty
key="javax.xml.parsers.DocumentBuilderFactory"
value="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
<arg value="packager.properties"/>
</java>
rackspace-oxygen.jar is created from extracting all the classes from deployer.jar, deployerUtils.jar, serializer.jar, and log4j.jar and jar'ing them into oxygen/tools/jwsPackager/lib/rackspace-oxygen.jar
Also, I had to include a META-INF/MANIFEST.MF file inside rackspace-oxygen.jar which had the entry:
Main-Class: ro.sync.jws.JwsPackager
3. Create oxygen/tools/jwsPackager/lib/rackspace-oxygen.jar as described in the previous step.
Once I did those 3 things I was able to create the oxygenJWS.zip by invoking the ant shell script via a maven's ant plugin. It seems like once you invoke the shell script or the ant build.xml in maven, the java class path specified in the build.xml is totally ignored. I tried so many different path variations and other ant command combinations but I could never get it to work. In the end, the steps I mentioned above was the only way I could get it to work. If you have any suggestions on a better way to do this with maven, your input would be appreciated.