On 25 Aug 2005, at 07:07, Petar Tahchiev wrote:
On 24/08/05, Stephen Morrison <[EMAIL PROTECTED]> wrote:
On 24 Aug 2005, at 16:56, Petar Tahchiev wrote:
On 24/08/05, Stephen Morrison <[EMAIL PROTECTED]> wrote:
On 24 Aug 2005, at 16:20, Petar Tahchiev wrote:
On 24/08/05, Stephen Morrison <[EMAIL PROTECTED]> wrote:
On 24 Aug 2005, at 15:03, Petar Tahchiev wrote:
Hi,
I'm trying to build an Ant project that uses some Apple Cocoa
classes.
These are stored as .class files and not as jars. They reside
in a
completely different folder to my project. I can compile and run
my
program by referencing these from the command line as follows:
javac -classpath /System/Library/Java:. MyProgram.java
java -classpath /System/Library/Java:. MyProgram
Is there a way I can replicate this functionality using Ant and
add
the
directory (System/Library/Java) to the classpath?
I've tried solutions from the Ant documentation and the archives
of
this list but haven't been able to get anything to work yet.
Thanks in advance,
Steve.
You can always use the <compilerarg> task to pass arguments to
the
compiler,
but rather why don't you try
<path id="compile.cp">
<fileset dir="YOUR DIR">
<include name=""/>
</fileset>
</path>
and later on call the classpath using <javac srcdir="" destdir=""
classpathref="compile.cp"/>
Or just use <classpath>
--
Regards, Petar!
I tried the compilerarg task but got the error "Could not create
the
task or type of task: conpilerarg". I declared this as
<compilerarg
line="-classpath /System/Library/Java/"/>.
I also tried the other methods you listed but I still got the
class
not
found error. My build.xml file was generated for my by my IDE
Xcode
and currently looks like this. Sorry if I am missing something
obvious
but I am totally new to Ant.
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyGame" default="jar" basedir=".">
<property name="src" location="src"/>
<property name="bin" location="bin"/>
<property name="lib" location="lib"/>
<property name="dist" location="dist"/>
<property name="jarfile"
location="${dist}/${ant.project.name <http://ant.project.name> <
http://ant.project.name> <
http://ant.project.name>}.jar"/>
<property name="compile.debug" value="true"/>
<fileset id="lib.jars" dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<path id="lib.path">
<fileset refid="lib.jars"/>
</path>
<target name="compile" description="Compile code">
<mkdir dir="${bin}"/>
<mkdir dir="${lib}"/>
<javac srcdir="${src}" destdir="${bin}" includeAntRuntime="no"
classpathref="lib.path" debug="${compile.debug}">
</javac>
</target>
<target name="jar" depends="compile" description="Build jar">
<mkdir dir="${dist}"/>
<jar jarfile="${jarfile}" basedir="${bin}" manifest="Manifest">
<!-- Merge library jars into final jar file -->
<zipgroupfileset refid="lib.jars"/>
</jar>
</target>
<target name="run" depends="jar" description="Run jar file">
<java jar="${jarfile}" fork="yes" failonerror="true"/>
</target>
<target name="clean" description="Remove build and dist
directories">
<delete dir="${bin}"/>
<delete dir="${dist}"/>
</target>
</project>
My fault. I forgot to tell you that compilerarg is an optioanl
ant-contrib
task and if you want to use it you have to download the tasks from
the
ant-contrib site: http://ant-contrib.sourceforge.net/, also an
installation
howto is available there. But instead try this
<javac .........>
<classpath>
<pathelement location="yourdir"/>
</classpath>
</javac>
--
Regards, Petar!
Thanks for your help so far but I still can't get it to work.
Firstly
I tried the additions to javac that you outlined above but I still
got
the class not found error. I then tried downloading the ant-contrib
task. I have referenced this as outlined in the documentation and
copied the jar file to my lib directory of my project. But I still
get
the could not create task error. Below is the code I added to my
build.xml file. Is this correct?
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="./lib/ant-contrib.jar" />
</classpath>
</taskdef>
<compilerarg line="-classpath /System/Library/Java"/>
I suppose that the problem is that you may have not copied the
ant-contrib-version.jar to your $ANT_HOME/lib folder. I am still
curious
that
<javac srcdir="" destdir="">
<classpath>
<pathelement location="yourdir"/>
</claspath>
</javac>
doesn't work. Remember that you must ignore the package folders when
pointing "yourdir". Point only the top-root forlder.
--
Regards, Petar!
You were right I hadn't copied the file to the $ANT_HOME/lib folder.
But after doing that it now runs, but still gives the class not found
error. There are 2 possible problems as I can see it. Either I'm
referring to the directory wrongly, or else I haven't defined the
compilerarg statement correctly.
When I refer to my directory which is /System/Library/Java this is the
reference from the root folder on my hard drive, and is the top root
folder of the package I want to use. Could it be that Ant is looking
for that folder from within the current folder my Ant project is
stored
in and not the root folder of my computer? In which case how can I get
it to point to the computers root directory? I thought starting with /
would do that.
Your vision is quite true . The / symbol represents the root folder in
Unix,
so ant should find the folder you are passing as an argument.
Alternatively I could be defining the compilerarg statement wrongly.
Firstly I have placed it within the <javac> tags. Is this the correct
location? Also, is the compilerarg statement below the correct way to
carry out the javac command line statement below it?
<compilerarg line="-classpath /System/Library/Java"/>
this should be
<compilerarg value="-classpath /System/Library/Java/"/>
javac -classpath /System/Library/Java:. MyProgram.java
Thanks.
Yes you are right that this fragment is wrong. First of all to ensure
you
have your tasks in your classpath use:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="ANT_HOME/lib/ant-contrib.jar"/>
</classpath>
</taskdef>
as "net/sf/antcontrib/antcontrib.properties" describes every
additional task
and it is placed in your ant-contrib.jar so you have to add it like a
classpath. Second your javac task should look something like this:
<javac srcdir="SRC" destdir="DEST">
<compilerarg value="-classpath"/>
<compilerarg value="DIRECTORY/"/>
</javac>
You can't just place <compilerarg value="-classpath DIRECTORY"/>
because
there is a blank space between -classpath and DIRECTORY and it will get
quoted. So you put the two strings as separate arguments. I tested it
on my
machine and it worked fine. Although I was a liitle bit confused
because I
have never used compilerarg to pass a directory to the classpath. I
most
oftently use a
<path id="compile.cp">
<pathelement location="DIRECTORY/"/>
</path>
---------------------
<javac srcdir="" destdir="" classpathref="compil.cp"/>
structure and it always wokes fine. Anyway I hope I helped.
P.S Dont forget to exclude any package directories and to place a /
after
DIRECTORY.
--
Regards, Petar!
Many thanks for all your help Petar. Sadly it still won't work. I
know for a fact my directory is correct because it works when I compile
and run the program from the command line. But from within my IDE
Xcode I still get the class not found error. I have copied my entire
build.xml file below. As you can see its laid out exactly as you
suggested. Unless there is some error in another part of the file
preventing this from working, I can only assume the problem lies with
the IDE, and if I can't find out the problem I will have to look for an
alternative.
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProgram" default="jar" basedir=".">
<property name="src" location="src"/>
<property name="bin" location="bin"/>
<property name="lib" location="lib"/>
<property name="dist" location="dist"/>
<property name="jarfile"
location="${dist}/${ant.project.name}.jar"/>
<property name="compile.debug" value="true"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/Developer/Java/Ant/lib/ant-contrib-0.6.jar"
/>
</classpath>
</taskdef>
<fileset id="lib.jars" dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<path id="lib.path">
<fileset refid="lib.jars"/>
</path>
<target name="compile" description="Compile code">
<mkdir dir="${bin}"/>
<mkdir dir="${lib}"/>
<javac srcdir="${src}" destdir="${bin}" includeAntRuntime="no"
classpathref="lib.path" debug="${compile.debug}">
<compilerarg value="-classpath"/>
<compilerarg value="/System/Library/Java/"/>
</javac>
</target>
<target name="jar" depends="compile" description="Build jar">
<mkdir dir="${dist}"/>
<jar jarfile="${jarfile}" basedir="${bin}" manifest="Manifest">
<!-- Merge library jars into final jar file -->
<zipgroupfileset refid="lib.jars"/>
</jar>
</target>
<target name="run" depends="jar" description="Run jar file">
<java jar="${jarfile}" fork="yes" failonerror="true"/>
</target>
<target name="clean" description="Remove build and dist
directories">
<delete dir="${bin}"/>
<delete dir="${dist}"/>
</target>
</project>