Hi i am able to compile my java program thru ant, but its failing to run it. For compiling <target name="build"> <javac srcdir="." /> <java classname="${main}" classpath="${classpath}"/> </target> Can any one tell the same for running the java class file. Thanks Srinivas
Kieran Bee
Greenhorn
Joined: Jan 30, 2003
Posts: 17
posted
0
What are the error messages? What are the values of 'main' and 'classpath'. Is the xml you gave supposed to compile and run the code, or just compile it? From the ant manual, running a java class goes something like:
srinivasrao marri
Ranch Hand
Joined: Feb 13, 2001
Posts: 61
posted
0
hi my java code is class test{ public static void main(String args[]) { System.out.println("welcome to ant"); } } and i made it to compile thru ant and the code is for build.xml file i written is <?xml version="1.0"?> <!-- build file for lesson 1 --> <project name="tutorial" default="build" basedir="."> <target name="build"> <javac srcdir="." /> <java classname="${main}" classpath="${classpath}"/> </target> </project> for the same program if i want to make it run what kind of line of code i need to add for build.xml? Thanks srinivas
Kieran Bee
Greenhorn
Joined: Jan 30, 2003
Posts: 17
posted
0
I'm guessing that the values of 'classpath' and 'main' are not set. In which case
<target name="main" depends="compile,run" /> </project> and try again.
saimurali
srinivasrao marri
Ranch Hand
Joined: Feb 13, 2001
Posts: 61
posted
0
i made my class public, with this my build.xml is running fine, the code i mentioned above is the one i used. i hope the reason to make my class public is , the ant itself if a java class file and its try to use another class file, if i declare it as public , then it can have access to it. i welcome any further discussion on this. thanks srinivas
Kieran Bee
Greenhorn
Joined: Jan 30, 2003
Posts: 17
posted
0
You can't run a method on a non-public class in the way it is invoked through Ant, that includes the Main method
srinivasrao marri
Ranch Hand
Joined: Feb 13, 2001
Posts: 61
posted
0
u mean to say this way: class HelloWorld{ void method1(){ System.out.println("i am in method 1"); } public static void main(String args[]){ HelloWorld hw=new HelloWorld(); hw.method1(); } } o/p: i am in method 1 this i did without ant.... could u pls elaborate u'r sentence... Thanks srinivas [ February 25, 2003: Message edited by: srinivasrao marri ]
Sri Kor
Ranch Hand
Joined: Sep 03, 2001
Posts: 35
posted
0
I have similar problem. When I tried to run my java application with Ant build file, My application opens and closes immidiately. I think, ant is killing the process immediately.Any comments Thanks
SCJP2<br /> <br /><a href="http://www.primeguru.com" target="_blank" rel="nofollow">Share Your Personal Experiences</a>
srinivasrao marri
Ranch Hand
Joined: Feb 13, 2001
Posts: 61
posted
0
send ur build file so that we can exactly come to know the problem
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.