This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Execute my java program with Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Execute my java program with Ant" Watch "Execute my java program with Ant" New topic
Author

Execute my java program with Ant

srinivasrao marri
Ranch Hand

Joined: Feb 13, 2001
Posts: 61
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
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

The line you already have:
<java classname="${main}" classpath="${classpath}"/>
will probably do it. You just need to set the properites main and classpath to the main class ("test") and the classpath (".") respectively.
srinivasrao marri
Ranch Hand

Joined: Feb 13, 2001
Posts: 61
why dont u give that line of code for property, i think that will give more clarity.
thanks
srinivas
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
What Greg means is:
include in the build.xml
<property name="main" value="test" />
<property name="classpath" value="." />
then <java classname="${main}" classpath="${classpath}"/>
will do the job.
HTH
srinivasrao marri
Ranch Hand

Joined: Feb 13, 2001
Posts: 61
<?xml version="1.0"?>
<!-- build file for lesson 1 -->
<project name="tutorial" default="build" basedir=".">
<property name="main" value="test" />
<property name="classpath" value="." />
<target name="build">
<javac srcdir="." />
<java classname="${main}" classpath="${classpath}"/>

</target>
</project>
the above one is giving me the below given error:
build:
[javac] Compiling 1 source file
[java] java.lang.IllegalAccessException: Class org.apache.tools.ant.taskdefs.ExecuteJava can not access a member of class test with modifiers "public static"
BUILD SUCCESSFUL
Total time: 3 seconds
This is done for the same java program.
Could u find why this error come. what is the wrong in my build file?
Thanks
srinivas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execute my java program with Ant