• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

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
0
rrz
Asked:
rrz
  • 11
  • 8
  • 6
1 Solution
 
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
0
 
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>


0
 
CEHJCommented:
Sorry, of course the command is

ant -Dclassname=NewTest [run]

(where run is optional)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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.  
0
 
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.
0
 
CEHJCommented:
The java task needs a classname unfortunately
0
 
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
0
 
objectsCommented:
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 :)
0
 
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
0
 
objectsCommented:
> 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
0
 
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.
0
 
objectsCommented:
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.
0
 
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.  
0
 
objectsCommented:
:)

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.

0
 
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
0
 
objectsCommented:
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.
0
 
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
0
 
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 ?  
0
 
CEHJCommented:
>>CEHJ , TextPad costs $30  

Sorry. I used it for years before paying. It uses a pretty unintrusive nag screen
0
 
CEHJCommented:
:-)
0
 
objectsCommented:
> 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

0
 
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
0
 
objectsCommented:
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 ;)
0
 
rrzAuthor Commented:
I guess we beat this to death. Thanks for your comments.    rrz
0
 
objectsCommented:
no worries :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 11
  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now