java - How do you configure Ant to get to run selections from the class? -


uhm... srry if there's strange how word things since it's first time asking in site this. there's still lot of things don't understand i'll best try , elaborate problem.

new apache ant, tried following steps running basic program apache manual, configuring bit try of different code. basically, using ant compile, ant jar, , ant run works out fine.

following build.xml setup provided, tried yes-no user input seemed turn out okay.

build.xml

<project>  <target name="clean">     <delete dir="build"/>  </target>  <target name="compile">               <javac srcdir="src" destdir="classes" />   </target>  <target name="jar">         <jar destfile="build/jar/circle.jar" basedir="classes">          <manifest>             <attribute name="main-class" value="circle"/>          </manifest>     </jar> </target>  <target name="input">      <input message="do want show details of circle?" validargs="y,n" addproperty="do.delete"/>     <condition property="do.abort">         <equals arg1="n" arg2="${do.delete}"/>     </condition>     <fail if="do.abort">build aborted user.</fail> </target>  <target name="run" depends="input">     <java classname="circle" fork="true">          <classpath path="classes" />     </java> </target> 

circle.java

import java.lang.*; public class circle{ public static void main(string[] args){      int radius;     double circumference;     double areaofcircle;          radius=10;                   circumference =2* 3.1416*radius;                 areaofcircle = 3.1416 * radius *radius;      system.out.println();     system.out.println("********************************************************");     system.out.println("*  radius of circle   " + radius +"                 *");     system.out.println("*  circumference of circle   " + circumference +"   *");     system.out.println("*  area of circle   " + areaofcircle +"             *");     system.out.println("********************************************************"); }  

}

how configure can put selection statement asking user input in source code? removing input target in buildfile , putting "do want show details of circle?" in circle file.

from understand, ant can run classes without need main class (?).

incorrect ant can run compiled java classes. "main" method standard entry point java program.

so there 2 problems code.

  1. no main method defined in main class (specified in manifest of jar)
  2. you invoking class incorrectly.

either leverage fact have main class defined

<target name="jar">     <jar destfile="myprog.jar" basedir="classes">         <manifest>             <attribute name="main-class" value="circle"/>          </manifest>     </jar> </target>  <target name="run" depends="jar">     <java jar="myprog.jar" fork="true"/> </target> 

or run code specifying classname , classpath.

<target name="run" depends="jar">     <java classname="circle" fork="true">         <classpath>             <pathelement path="classes"/>         <classpath>     </java> </target> 

for full , complete example (also covers advanced topic of managing 3rd party dependencies), see following:


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -