Ant , use it for a mini IDE ?

I am teaching a newbie. Unfortunately his home computer is rather old (Win98), slow and weak. His machine will not handle a big pig of a IDE. Ok, he can type at the command line. But, that gets old fast, as we all know. So, my idea is to use ant to save him a lot of typing. I came up with a simple build.xml file.  

<?xml version="1.0"?>
<project name="CompileAndRun" default="run" basedir=".">
  <target name="compile" description="Compiles Test.java">
                               <record name="Test.txt" loglevel="debug" action="start" append="false"/>
                               <javac srcdir="." destdir="." />
  </target>
  <target name="run" depends="compile" description="runs Test.class">
                               <java classname="Test" classpath="."/>
  </target>
</project>

I installed Apache Ant version 1.6.5  and made a directory called codeTest. Inside codeTest I placed the build.xml file, a shortcut to Command Prompt, and a file called Test.java  . This works great. He writes a few lines of code in the Test.java file and he can test it by typing  "ant" at the command line. Wow! He is climbing that learning curve fast now. He is happy with this. But I want him to be able to name his source code any name he chooses. I don't want him to have to name his class "Test" everytime. So, there is my problem.
I can't figure out how to put a variable or a wildcard in the classname attribute of <java> task. I tried <java classname="**/*.class" classpath="."/> , <java classname="all" classpath="."/> ,and a lot of different things but I am unsuccessful so far.  Do you have any ideas ?      rrz
LVL 28
rrzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzAuthor Commented:
If,  we can't do what I want to do, then points go to anyone with an improvement to the build file. Please keep in mind that it is just for a newbie.   rrz
CEHJCommented:
Pass it to ant as a parameter

ant -Dclassname=NewTest compile


<target name="run" depends="compile" description="runs Test.class">
                               <java classname="${classname}" classpath="."/>
  </target>


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Sorry, of course the command is

ant -Dclassname=NewTest [run]

(where run is optional)
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

rrzAuthor Commented:
>Pass it to ant as a parameter

>ant -Dclassname=NewTest compile  
Are you suggesting that we *type* that at the coommand line ?  I was hoping that we could just drop in a new source file into the codeTest directory and type "ant".    But I guess that is a working solution. I will keep playing with this,thanks CEHJ.  
rrzAuthor Commented:
I was hoping that the core type  FileSet would help but I can't seem to reference one inside <java>'s  classname attribute.
CEHJCommented:
The java task needs a classname unfortunately
rrzAuthor Commented:
>The java task needs a classname unfortunately  
I guess we are stuck then. We can leave it the way I posted originally or use your idea.  

  <?xml version="1.0"?>
<project name="CompileAndRun" default="run" basedir=".">
  <target name="compile" description="Compiles Test.java">
                               <record name="Test.txt" loglevel="debug" action="start" append="false"/>
                               <javac srcdir="." destdir="." />
  </target>
  <target name="run" depends="compile" description="runs a class file">
                               <java classname="${c}" classpath="."/>
  </target>
</project>

and type at command line the following.   ant  -Dc=MyClassName  
Perhaps we will use both ideas. We could have two separate  directories.    rrz
Mick BarryJava DeveloperCommented:
a bat file should be able to do that, and run your bat file from ant.
How would u handle >1 class file though, a little bit of education may be a better way to go :)
rrzAuthor Commented:
>a bat file should be able to do that, and run your bat file from ant.
I will need  guidance. I don't know how proceed on that idea.
>a little bit of education may be a better way to go :)    
Always a good idea.  But I am not sure what you are implying here.  Please elabrate. I am open. Thank you for your time.    rrz
Mick BarryJava DeveloperCommented:
> Always a good idea.  But I am not sure what you are implying here.  Please elabrate. I am open. Thank you for your time.    rrz

teach them how to run a class and just use ant to do the build

ie.

java MyClass
rrzAuthor Commented:
>teach them how to run a class and just use ant to do the build
He already knows how to compile  and run a class file.  I am just trying to minimize the *typing*.  If, the newbie just uses the command line, then after changing his code he must type  " javac MyClass.java "   then type "java  MyClass ".   If he cycles through this 100 times then it becomes a real drag.  My idea is to give him a break and just require that he type  " ant ".  Please bear in mind that his computer is old.  Otherwise he could use an IDE  and click a button for each cylce.
Mick BarryJava DeveloperCommented:
You don't need an IDE, a decent editor that can configure buttons/key strokes to run commands will do the job.
Have a look at UltraEdit or similiar.
rrzAuthor Commented:
>Have a look at UltraEdit  
$40  WoW!  Maybe we should save the money and use towards a new computer and afterwards download Netbeans.  
Mick BarryJava DeveloperCommented:
:)

there are good free editors around, mentioned ultraedit specifically becuase i've used it for development and would recomend it. and for someone learning I'd probably recomened it even over netbeans :)
It has an evaluation license, can't remember what it does when it expires.

rrzAuthor Commented:
>>a bat file should be able to do that, and run your bat file from ant.    
I played around with a  bat file for a while. But I could not see a way it would help.
Thanks for the ideas, objects.

I am ready to award points to CEHJ.  His idea of adding the classname property to the command line was the only good suggestion. If, no one comes up anything else, then I will close tomorrow.    rrz
Mick BarryJava DeveloperCommented:
Whats wrong with using a decent editor? they wouldn't have to even touch the command line then, even to do a build.
a free example would be jedit but there are many other choices.. There are lots of developers who work quite happily without an IDE.
And running the class from the command line is actually shorter and easier than running via ant ;) Using ant requires more typing, not less.
CEHJCommented:
I use TextPad quite a bit. It has support for compiling and running within. It has support for code macros to automate entering bit of code. It's free.

www.textpad.com
rrzAuthor Commented:
First of all , I want to thank you both for your time.    
CEHJ , TextPad costs $30  
Objects
>Whats wrong with using a decent editor?  
Nothing wrong.    jEdit does look ineresting though.
>And running the class from the command line is actually shorter and easier than running via ant ;) Using ant requires more typing, not less.    
I disagree.  Using my first method all we type is "ant"   Using the method suggested by CEHJ  we would type is "ant  -Dc=MyClassName"   At the command line we would first type "javac MyClassName.java" then we type "java MyClassName"    

 I have been using PFE    http://www.lancs.ac.uk/staff/steveb/cpaap/pfe/default.htm    for seven years now and I never got around to changing to anything else.  I have used NetBeans and Eclipse briefly. Frankly they just cramp my style. I intend to use Netbeans 5  someday soon though.
 I spend most my time writing JSPs. I just throw them into Tomcat.  When I need a Servlet or a bean then I have Ant to compile, jar and put it into Tomcat.
 
For the newbie, my first thought was to keep it simple.  But maybe I am stupid.  So, I have a question to all listeners.  
How should the newbie begin ?  
CEHJCommented:
>>CEHJ , TextPad costs $30  

Sorry. I used it for years before paying. It uses a pretty unintrusive nag screen
CEHJCommented:
:-)
Mick BarryJava DeveloperCommented:
> Using the method suggested by CEHJ  we would type is "ant  -Dc=MyClassName"   At the command line we would first type "javac MyClassName.java" then we type "java MyClassName"    

no, you'd still use ant to do the build thats what it for

ant
java MyClassName

less keystrokes :) and more flexible, plus you learn a bit

rrzAuthor Commented:
>less keystrokes :) and more flexible, plus you learn a bit    
objects, I really do want to understand what you are trying to explain to me.    
Using the buide file I  posted at the top,   We just typed "ant"    But that method required us to use the same class name every time. That is because I did not want the newbie to alter the build file.    
Using CEHJ's method(the second build file I posted), we just had to type   "ant  -Dc=MyClassName"      The newbie just placed his source code into the directory(with the build file and the shortcut to the command prompt).
Using either of these two methods, Ant compiles and runs the code.  
If I understand you correctly, you suggest that we type "ant"  and hit the enter button to compile(using a suitable build file),  then to run it type "java MyClassName"  and then hit the enter button again.
If I am thinking correctly your method is one more keystroke(hitting the enter button twice). If I wrong then I owe you a beer.   rrz
Mick BarryJava DeveloperCommented:
i wasn't counting the enter key :)

you could of course put that into a bat and have the best of both worlds.
you don't really want to have to do a build everytime you want to run an app ;)
rrzAuthor Commented:
I guess we beat this to death. Thanks for your comments.    rrz
Mick BarryJava DeveloperCommented:
no worries :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.