Hi folks.
Newbie (to the newsgroup) here -- hopefully not stomping on
any rules... :)
This is a cutesy little snippet for Java / *nix / *nux
programmers. It's been done for other languages but I
haven't come across any examples for Java so figured I'd
throw one together. Tested only in bash.
The idea: a .java file that compiles itself, builds its own
javadoc, and executes itself.
Source code:
http://www.mountaingrouse.com/software/self_compiling_class.java
Javadoc:
http://www.mountaingrouse.com/software/self_compiling_class/
Suggestions and bug reports are welcome. Thanks and enjoy,
Johann Tienhaara
jtienhaara@yahoo.com
> Newbie (to the newsgroup) here -- hopefully not stomping on
> any rules... :)
Don't think so, seems mostly relevant to java :-)
> This is a cutesy little snippet for Java / *nix / *nux
> programmers. ...
[quoted text clipped - 3 lines]
> Source code:
> http://www.mountaingrouse.com/software/self_compiling_class.java
Amazing :-)
I think it can be further simplified, by using this as first line:
//bin/sh << "EOF2"
By putting the "end word" under double-quotes, you no longer need
to backslash-escape each dollar-sign in the actual script-part of
the file.
You should also use this technique for "cat >/dev/null"-ing the
actual java source-code, because otherwise, eventual occurrences
of e.g. `date` (and just as well also nastier things than that)
in the java-part would still be executed! Not that any backticks
or $(...) were appearing in your sample, but I see this more as
a recipe to wrap simple java-code, and some arbitrary thusly
wrapped code could easily contain such thing inside a string-
constant or comment.
Anyway: using //bin/... for the switching... cool! :-)
jtienhaara@yahoo.com - 18 Jan 2008 20:56 GMT
> //bin/sh << "EOF2"
> By putting the "end word" under double-quotes, you no longer need
> to backslash-escape each dollar-sign in the actual script-part of
> the file.
Thanks for the feedback, and especially for the great
suggestion Andreas. I wish I had known about << "EOF" years
ago! :)
I updated the source code to incorporate Andreas's
suggestion. Although this info doesn't pertain to Java,
just a quick note that capturing $0 and $* inside << "EOF"
is a bit of a mind-bender... :) Interestingly I had to
start the new version of the .java file off with //bin/cat
(instead of //bin/sh) in order to get at $0 and $* further
down in the file.
Anyway thanks much for the tip! Cheers and enjoy,
Johann
> Hi folks.
>
[quoted text clipped - 12 lines]
>
> http://www.mountaingrouse.com/software/self_compiling_class.java
Neat stuff. Thanks for posting it.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |