• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to execute class from build.xml

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am not able to execute the java class SendMail from build.xml. I am using the following statement to do that --

<target name="email" >

<java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" />
</target>

I have also tried using it with fork but to no avail --

<target name="email" >

<java classname="util.SendMail" fork="true" classpath="${test.dest}" classpathref="testcase.path" />
</target>


Apart from the the above statement everything runs successfully in the build.xml file. The ANT does not report any error even though the last statement in the build.xml is not being picked up.

The purpose of the SendMail class is to call the zip function in the TestUtil class to zip the reports and then email it.

When I run the SendMail class on its own it runs just fine(it zips the reports and also emails it) but somehow its not getting picked up in the build.xml file.

Could anybody please provide a solution to this.

Please find the respective classes,build.xml & the folder structure for the gmail framework attached.

Also, when I try and run the entire project on eclipse with the suiterunner for Junit, it runs successfully.

I am not very good with ANT so any help in this regard will be really appreciated.









Thanks

Ash
Folder-Structure.jpg
[Thumbnail for Folder-Structure.jpg]
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ash,
Welcome to CodeRanch! It is strange you aren't getting an error message. Can you try adding 4 debugging statements?

The first two are in Ant before and after the java call:


The other two are the first and last line in your SendMail class.

Knowing which of these four run will be immensely helpful in narrowing down the problem.

Another idea to try is calling Ant with the verbose flag. It may give you more detail about where the problem lies.
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,


Thanks a lot for the quick reply.

I just did exactly what you asked me to but unfortunately the msg was not echoed nor did I get any msg from the Java class after adding the debugging statements.

So it looks like its not picking up the statement to execute the java class. Not sure if the syntax of the statement is correct in my code.

I have edited my original post and attached build.xml and the sendmail class.


Thanks

Ash


 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ash,
That means it isn't running the "email" target at all. I don't see the email target listed as a dependency for any of the other targets. What command are you using to run Ant? What target are you calling?
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I do on the command prompt -

ant clean

ant compile

ant run
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say target, do you mean which class I am trying to call from build.xml .

I am trying to call the sendmail class from build.xml.
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of my project is to

1)run the junit tests in the FirstSuiteRunner
2)produce the reports
3)zip & email the reports

Its performing the first 2 steps successfully but not the 3rd step which is meant to be achieved by executing the sendMail class at the end of the build.xml file.

When I try and run the sendMail class on its own through eclipse it runs fine.

As you can see in the code for the sendMail class that it first calls a function TestUtil.zip(directory, zipfile) to zip the file and then it sends the email.

Thanks

Ash
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are actually doing an extra step. Ant runs what you ask and any dependencies.

When you say "ant clean", it just cleans. When you say "ant compile", it runs init, clean and compile. (Do you see why?) When you say "ant run", it just runs.

It is common to have all have depends on all the others so you can just say "ant all."
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just did what you asked me to but still not picking up the sendMail class from build.xml
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ash Modi wrote:Just did what you asked me to but still not picking up the sendMail class from build.xml


Can you show what your build file looks like after the change and what Ant command you ran?
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



On the command prompt I navigated to the location of my project and then did the following

ant all

ant run
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's only half of what I suggested. For ant all to work, you need to setup all so it runs the others. For example:

<target name="all" depends, compile, run, email">
 
Ash Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I am pretty new to ANT. Not sure how to do it.
 
    Bookmark Topic Watch Topic
  • New Topic