Ant classpath modification for mail task

M

moi

Hello,

how can i use the "mail" task in my Ant script without modifying my system
CLASSPATH? I would like to change the classpath in the build.xml file, but
i don't manage to make the mail task to use the new classpath.

Does anyone know how to do this?

<project basedir="." default="mail" name="myProject">
<target name="mail">
<!-- How to use this ? -->
<classpath>
<pathelement path="${java.class.path}"/>
<fileset dir="javamail/lib">
<include name="*.jar"/>
</fileset>
</classpath>


<!-- Warning: needs javamail libs in the classpath -->
<mail mailhost="mail.lan"
subject="Performance tests results"
encoding="mime">
<from address="from@lan" />
<replyto address="from@lan" />
<to address="to@lan" />
<message>Report files</message>
<fileset file="file1.txt"/>
<fileset file="file2.txt"/>
</mail>
</target>
</project>
 
R

Roedy Green

how can i use the "mail" task in my Ant script without modifying my system
CLASSPATH? I would like to change the classpath in the build.xml file, but
i don't manage to make the mail task to use the new classpath.

look at how ant launches. It gets all its classpath information from
the command line. You can add something to ant's classpath without
disturbing the system classpath.

Similarly you can do a SET command that only changes the classpath for
the current script.

If you really don't want anything else seeing this extra classpath,
you are going to need to launch a new JVM from within ant.
 
M

moi

Roedy said:
look at how ant launches. It gets all its classpath information from
the command line. You can add something to ant's classpath without
disturbing the system classpath.

well i would like to avoid this, the user doesn't need to know where are the
libraries since i distribute them.

Similarly you can do a SET command that only changes the classpath for
the current script.

i can't find any sample of this command use. Can you show me some example?

If you really don't want anything else seeing this extra classpath,
you are going to need to launch a new JVM from within ant.

in last resort
 
M

moi

Roedy said:
SET classpath=C:\;C:\dir\extra.jar

well, AFAIK, this is a MS-DOS command (i have an error puting it in my
build.xml script). I'm looking for an Ant command wich i can put inside my
build.xml.
 
R

Roedy Green

well, AFAIK, this is a MS-DOS command (i have an error puting it in my
build.xml script). I'm looking for an Ant command wich i can put inside my
build.xml.

The challenge for ant is Java.exe has already fired up. To change the
classpath dynamically ant would have to either start a custom class
loader or spawn a new jvm.

The java and executejava tasks let you provide a new classpath.

Unfortunately the mail task has no such parameter.

the only way I can think of doing what you want to do is to fire up
another JVM running ant and give it your mail script.

What I don't understand is why would the mail task care about your
fancy classpath?
 
R

Roedy Green

What I don't understand is why would the mail task care about your
fancy classpath?

in other words, why not just add it when you fire up ant adding it to
the system classpath on the command line if you don't want to use the
ext directory or the system classpath for some reason.
 
R

Raymond DeCampo

Roedy said:
look at how ant launches. It gets all its classpath information from
the command line. You can add something to ant's classpath without
disturbing the system classpath.

Similarly you can do a SET command that only changes the classpath for
the current script.

If you really don't want anything else seeing this extra classpath,
you are going to need to launch a new JVM from within ant.

ANT has a directory (probably lib) where it will include any jar in that
directory. Put the java mail jars there.

The gotcha (there's always a gotcha) is that ANT includes the "system
classpath", that is the classpath for ANT itself onto other classpaths
it uses to compile, etc. This may have a detrimental effect. There is
a switch in the build.xml to turn it off.

Ray
 
R

Roedy Green

The gotcha (there's always a gotcha) is that ANT includes the "system
classpath", that is the classpath for ANT itself onto other classpaths
it uses to compile, etc. This may have a detrimental effect. There is
a switch in the build.xml to turn it off.

Look at ant.bat. The way ANT gets that classpath is by manually
adding to a -D system property on the command line. If you change the
way ant is invoked, you can also change its initial starting
classpath.

To me, simply adding a jar to the ext directory is the no-hassle way
to deal with extra jars.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top