views:

59

answers:

2

I look at a lot of small Java programs. It would be convenient if I could set up a directory (or directory structure) on my Mac where any time I add a .java file, javac automatically runs and attempts to compile that file. I've briefly looked into Automator actions, but found nothing that fits the bill. Then I got to thinking: on my PC, I would use the .Net FileSystemWatcher class and write the code myself. But before I try that on my Mac with Mono, I want to ask the community for other ideas. Any advice is appreciated. Thanks.

+1  A: 

If you have all the .java files available at the start, you could write a shell script to compile them all in one run -- in different directories if you need to.

If you explained why you would want this, maybe I/we could be more helpful.

Thomas
Thanks for the suggestion. As for why: I'm teaching an introductory programming course, so I look at a lot of small Java programs. It's not a killer to work on the command line, but I got to thinking about how to streamline things.
Alan
Having taught introductary programming courses myself, I guessed as much. The command line *is* great for streamlining things, if you ask me.
Thomas
+1  A: 

In JDK6 you can programmatically compile, so you could write your own program to do this, which may be slightly better than doing it in mono.

So you would just have a program that is always running, it looks for either any new files or a file that has been changed since the last check and then just compiles them, and you may want it to pass information to a dashboard window when there are errors, and perhaps some status info so you know it is working.

http://binkley.blogspot.com/2005/09/programmatically-compiling-java-in-jdk.html

James Black
Very interesting idea. Thanks!
Alan