King Kamal
King Kamal

Reputation: 205

How to include external class files during build in ant

I have a package(with some outdated Java files) which i need to build using ant tool. I have some updated classes for which source is not available. So, I need to add the updated class to the jar during build and skip the outdated Java files from the build. Please let me know how to achieve this.

For example - I dont have the updated source java file for com.org.auth.ABC.Java, but i have the updated class file which i got from the another source ie com.org.auth.ABC.class. During build i need to point to the updated class(com.org.auth.ABC.class) for this class alone and create a new jar.

Please find how i am currently pointing to the class files below.

<target name="xxx.jar" depends="xjc,compile">
    <jar destfile="${dist.dir}/xxx.jar">
        <fileset dir="${classes.dir}" includes="**/*.class"/>
        <fileset dir="${jaxb-classes.dir}" includes="**/*.class"/>
        <fileset dir="${jaxb-source.dir}" includes="**/bgm.ser,**/jaxb.properties"/>
    </jar>
</target>

Upvotes: 1

Views: 4699

Answers (1)

Sanjeev
Sanjeev

Reputation: 9946

If you want to leave some package from compilation you can use excludes attribute of fileset ant tag.

for example:

  <fileset dir="src/">
      <exclude name="**/dir_name_to_exclude/**" />
  </fileset>

In order to include the specified class in compilation you can put the containing folder in your class-path using ant.

  <path id="project.class.path">  
    <pathelement location="lib/"/>  
    <pathelement path="${java.class.path}/"/>  
    <pathelement path="path to your class file's base folder"/>  
  </path> 

  <javac srcdir="${src.dir}"
     destdir="${classes.dir}"
     classpathref="project.class.path">
     ... put source files here..
  </javac>

And if you want to include that class-file in your jar then add it to fileset using include tag:

  <fileset dir="classfiles">
     <include name="your class file name"/>
  </fileset>

Hope this helps

Upvotes: 2

Related Questions