Coder
Coder

Reputation: 3130

Ant script to generate Jar - Reference not found error

I have following ant script to generate the jar file

<project name="myProject" basedir="." default="jar">
<property name="src" value="Java Source"/>
<property name="output" value="bin"/>

<target name="compile" depends="create">
    <javac destdir="bin">
        <src path="${src}"/>
        <classpath refid="myProject.classpath"/>
    </javac>
</target>

<target name="jar" depends="compile">
    <jar destfile="myProject.jar">
        <fileset dir="bin"/>
    </jar>
</target>


<target name="clean">
    <delete dir="${output}"/>
</target>

<target name="create" depends="clean">
    <mkdir dir="${output}"/>
</target>

When I run ant script i get following error

Reference myProject.classpath not found.

I am not sure how to solve this error. It requires path of .classpath file ? I also tried with

refid="classpath"

and it didnt work.

Can anyone help please! Thanks

Upvotes: 5

Views: 11517

Answers (1)

Edmon
Edmon

Reputation: 4872

You need to define first something like because right now MyProject.classpath is not defined:

<classpath>
  <pathelement path="${classpath}"/>
</classpath>

assuming that your classpath has what you need.

If it does not, create another entry under classpath element that has references to jars or whatever you need, or you need to custom specify path:

  <path id="MyProject.classpath">
   <pathelement location="lib/"/>
   <pathelement path="${classpath}/"/>
   <pathelement path="${additional.path}"/>
  </path>

http://ant.apache.org/manual/using.html#path

Upvotes: 4

Related Questions