Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute my java program with Ant

 
srinivasrao marri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2987
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont u give that line of code for property, i think that will give more clarity.
thanks
srinivas
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic