Avatar of ssherlock
 asked on

Classpath error when calling ant from cruisecontrol

Using CruiseControl to build a web service I have the following in the build script to get the version of the build so that a directory can be built (named that version number) and the EAR file stored there.  This is so we can quickly get a archived builds (rather than extract from VSS by label and rebuild).
The question is how to get at a class within the WAR (that is already in the EAR)?  I am getting classpath errors with the following:
<!-- The following works fine and creates the GetVersion.class file, which is stored in the war file -->
<mkdir dir="src/appl/version"/>
<exec dir="src/appl/version" executable="cmd" output="src/appl/version/GetVersion.java" >
  <arg line="/c echo package appl.version; import appl.common.util.Utils; public class GetVersion { public static void main(String[] args) { System.out.println(Utils.VERSION); } }"/>
<ant antfile="build.xml" target="build_all"/>

<!-- The following fails due to a classpath error -->
<java classname="appl.version.GetVersion" outputproperty="dcp.version"/>

<!-- Any reference to dcp.version just adds ${dcp.version} rather than the hoped for version number -->
<vsslabel serverpath="S:/AppData/CH/AppDev/LWS/SourceSafe" vsspath="${vss.project}" label="Client ${dcp.version}" />
<mkdir dir="S:/AppData/CH/AppDev/Web service builds/DebitCardPaymentServerV002/${dcp.version}" />
<copy file="DebitCardPaymentServer.earV002.Prod" tofile="S:/AppData/CH/AppDev/Web service builds/DebitCardPaymentServerV002/${dcp.version}/DebitCardPaymentServer.earV002.Prod"/>
<copy file="DebitCardPaymentServer.earV002.UAT" tofile="S:/AppData/CH/AppDev/Web service builds/DebitCardPaymentServerV002/${dcp.version}/DebitCardPaymentServer.earV002.UAT"/>
JavaWeb ApplicationsProgramming

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
Mick Barry

>  which is stored in the war file

it can't access the class from the war file.
you'll need to have a copy in some directory and specify that directory using the classpath parameter of the java task

Tried that.  When being compiled the GetVersion.class file is created in the following directory: C:\lws_cruise\checkout\dcp_V002\jardir\WEB-INF\classes so I added that to the classpath (or thought I did) remembering to change \ for / but get the following errors in the cruisecontrol log:
<task location="C:\lws_cruise\build-dcpV002.xml:19:" name="java" time="0 seconds">
 <message priority="error">
 <![CDATA[ Could not find GetVersion. Make sure you have it in your classpath
      at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:138)
I've tried various connotations with no luck.

As a matter of interest where/how should I set the classpath?  Either in the build file i.e.
<java classname="GetVersion" outputproperty="dcp_version">
      <fileset dir="C:/lws_cruise/checkout/dcp_V002/jardir/WEB-INF/classes">
        <include name="GetVersion.class"/>
or somewhere else?

Figured it out.

I changed the cruisecontrol build script to the following:
<java classname="GetVersion" outputproperty="dcp_version">
         <classpath path="C:/lws_cruise/checkout/dcp_V002/jardir/WEB-INF/classes" />
rather than usuing the <fileset> tag above
Your help has saved me hundreds of hours of internet surfing.
Mick Barry

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.