Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Supposing you want to deploy only selected classes using ant from the ide to various orgs. This can be tricky because you need to ensure both your package.xml and your payload (either your classes directory or a zipfile) contain exactly the same files.

Is there a neat way to do this by defining set ant targets with wildcards for the files to be included?

share|improve this question
up vote 5 down vote accepted

First, you need to ensure your package.xml contains at least what you are deploying. It may contain more, but not less.


UPDATE: It is even easier to do this:


Next, setup an ant target in your build.xml which looks something like this:

<target name="QADeployClass1And2">
    <delete file=""/>
    <zip destfile="">
        <fileset dir="src" includes="classes/Class1.*"/>
        <fileset dir="src" includes="classes/Class2.*"/>
        <fileset dir="src" includes="package.xml"/>
    <sf:deploy zipFile="" allowMissingFiles="true"
        username="" password="**********" 
    <delete file=""/>

When you run this target you will deploy only Class1.cls and Class2.cls. I also find it useful to place the username, password and serverurl on the target so that I can use a different ant target for each target org without having to switch out the file.

I use the zipfile approach (1) because this allows me to easily and centrally control which files go into the payload. If you wish to use a folder with deployRoot you need to make a temporary folder and copy in the files you need:

<target name="deploy1">
        <fileset dir=".\deploy\classes" includes="**/*.*"/>
    <copy file="deploy\package1.xml" tofile="deploy\package.xml"/>
    <copy todir=".\deploy\classes">
        <fileset dir=".\src\classes\" includes="Class1.*"/>
        <fileset dir=".\src\classes\" includes="Class2.*"/>
    <sf:deploy allowMissingFiles="true" username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="deploy"/>

In this example you could setup package1.xml to only include the files you want to deploy and it will overwrite package.xml when you run this ant target thus making allowMissingFiles="true" superfluous.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.