ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petar Tahchiev <paranoia...@gmail.com>
Subject Re: Referencing External .class Files In Classpath
Date Fri, 26 Aug 2005 11:35:03 GMT
On 25/08/05, Stephen Morrison <s.f.morrison@gmail.com> wrote:
> 
> 
> On 25 Aug 2005, at 15:41, Petar Tahchiev wrote:
> 
> > On 25/08/05, Stephen Morrison <s.f.morrison@gmail.com> wrote:
> >>
> >>
> >> On 25 Aug 2005, at 07:07, Petar Tahchiev wrote:
> >>
> >>> On 24/08/05, Stephen Morrison <s.f.morrison@gmail.com> wrote:
> >>>>
> >>>>
> >>>> On 24 Aug 2005, at 16:56, Petar Tahchiev wrote:
> >>>>
> >>>>> On 24/08/05, Stephen Morrison <s.f.morrison@gmail.com> wrote:
> >>>>>>
> >>>>>>
> >>>>>> On 24 Aug 2005, at 16:20, Petar Tahchiev wrote:
> >>>>>>
> >>>>>>> On 24/08/05, Stephen Morrison <s.f.morrison@gmail.com>
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> <
> >>>> 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 <http://ant.project.name> <
> http://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>
> >
> >
> > I am in a hurry right now so I will look further on your problem
> > tommorow
> > morning. Meanwhile you may try to test your application via console
> > instead
> > of in your IDE. If it works then you should add your jars in the
> > classpath
> > of your project. Also the problem may have been caused by not
> > inserting the
> > jars in the right place. Many IDEs have their own ANT_HOME. Elcipse's
> > is in
> > plugins/ant-1.6/. Try to run ant from the command line, and also it
> > would be
> > useful if you supply the stackTrace. We don't know which class isn't
> > found.
> > Right?
> > Hope that helps...
> >
> > --
> > Regards, Petar!
> >
> 
> Thanks Petar. I tried running ant from the command line and replied to
> this mail with the results shortly before you sent your reply. If you
> haven't yet seen it, it was just to say that I got the same problem
> doing it that way.
> 
> I think the jar is in the right place. Xcode allows you to modify the
> path where it searches for the ant installation and this is currently
> pointing to the correct place where I copied the file. Also, before I
> was referring to it wrongly and the project wouldn't compile saying it
> couldn't find compilerargs. When I fixed this it compiled OK. So I'm
> pretty sure its finding the compilerarg task OK.
> 
> As for the error I get its this:
> 
> Exception in thread "main" java.lang.NoClassDefFoundError:
> com/apple/cocoa/application/NSSpeechSynthesizer
> at SpeechSynthesiser.<init>(SpeechSynthesiser.java:11)
> at Game.<init>(Game.java:35)
> 
> The package its referring to is the Apple Cocoa speech synthesizer
> package. This is found on Macs in the folder /System/Library/Java
> which is the path I am pointing too. Like I said earlier if I use
> javac from the command line and not ant it picks this up OK. So I'm
> pretty certain the error is somewhere in my build.xml file. As it was
> system generated (minus the few additions I've made to try and fix
> this) I'm not sure if its 100% correct.



First of all I want to say that in my opinion your code looks fine. I am a 
little bit astonished by the part:
 <javac srcdir="${src}" destdir="${bin}" includeAntRuntime="no"
classpathref="lib.path" debug="${compile.debug}">
<compilerarg value="-classpath"/>
<compilerarg value="/System/Library/Java/"/>
</javac>
Maybe, I am not quite sure, so maybe there is a problem when using 
classpathref and <compilerarg value="-classpath"/>. I don't know whether 
some kind of confrontation could arise. Let me suggest you something. You 
have a
<path id="lib.path">
<fileset refid="lib.jars"/>
</path>
defined. Why don't you just add your folder to this path and then call 
classpathref="lib.path" in your javac task. Something like this should work:
<path id="lib.path">
<fileset refid="lib.jars"/>
<fileset dir="/System/Library/Java">
<include name="**/*.*"/>
</fileset>
</path>
Also tell me does your code now compile and breaks down during execution or 
you can't compile it at all?
-- 
Regards, Petar!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message