ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Morrison <s.f.morri...@gmail.com>
Subject Re: Referencing External .class Files In Classpath
Date Wed, 24 Aug 2005 15:49:16 GMT

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>}.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"/>

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