ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ivan \"Rambius\" Ivanov" <rambiusparkisan...@yahoo.com>
Subject Re: classpath and simultaneous builds
Date Mon, 06 Feb 2006 04:35:10 GMT
Hello,

--- Harshal Chavda <h_ant@rediffmail.com> wrote:

> Hello ant fraternity,
>                   I am a beginner in ant(version
> -1.6.3) 
First, I would suggest that you upgrade to the latest
version of Ant which is 1.6.5.

> and have 
> absolutely no knowledge of java(I can only write
> very simple java 
> programas in java).Can anyone please tell me "what
> is classpath and 
> how is it used"?

OK, classpaths specify a bunch of directories that
contain .class files and/or a list of .jar files.
Example, suppose you write an applicatrion that relies
of log4j[1] for doing its logging. You download log4j,
extract it and find log4j.jar. In order to use its
classes, Java must know where it should find it. So
you export a environment variable:
set
CLASSPATH=/path/where/you/extracted/log4j/log4j.jar

Pleaee note that it is possible that your application
relies on one classpath while compiling it, and a
slightly different classpath for running. For example,
you develop a JDBC application with oracle (and after
you are done with logging jar) you have to add the
oracle JDBC driver which is shipped in classes12.jar.
Usually, the JDBC driver is instanitiated via reflect
api like:
Class.forName("oracle.jdbc.driver.OracleDriver");

In this case you may not need classes12.jar to compile
the app, but you will need it while running the
application, so before you run it you do
set
CLASSPATH=/path/where/you/extracted/log4j/log4j.jar;/path/to/classes12.jar
(you still need log4j jar).

Usually, without a build tool like ant you would use
the second classpath as it is superset of the first
one. However, with ant you have much for flexibility
to reuse classpaths:

<path id="compile.cp">
  <pathelement
location="/path/where/you/extracted/log4j/log4j.jar"/>
</path>

<path id="runtime.cp">
  <path refid="compile.cp"/>
  <pathelement location="/path/to/classes12.jar"/>
</path>

<target name="compile">
  <javac ...>
    <classpath refid="compile.cp"/>
  </javac>
</target>

<target name="run">
  <java ...>
    <classpath refid="runtime.cp"/>
  </java>
</target>

Note that runtime.cp path references compile.cp. This
provides a level of "classpath hygiene". For path-like
structures in Ant see [2].

Regards
Ivan

[1]http://logging.apache.org/log4j/docs/index.html
[2]http://ant.apache.org/manual/using.html#path

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message