So far I've always compiled my application with
javac xxxx.java
and invoked them with
java xxxx.class
I wonder if there could be a way to invoke the application directly.
I know I could make an alias, alias xxxx 'java xxxx.class' and then
invoke xxxx, but this is not what I mean
I am thinking of a compilation like
cc xxxx.c -o xxxx or f77 xxxx.f -o xxxx
which generates a named executable xxxx (instead of a.out)
Or something like shell or awk scripts, which I could write into files
with the executable bit set (chmod +x) and prepend with things like
#!/bin/csh -f
#! /usr/bin/awk -f

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Gordon Beaton - 23 Feb 2007 10:26 GMT
> So far I've always compiled my application with
> javac xxxx.java
> and invoked them with
> java xxxx.class
Probably just "java xxxx" (*not* .class)
> Or something like shell or awk scripts, which I could write into files
> with the executable bit set (chmod +x) and prepend with things like
> #!/bin/csh -f
> #! /usr/bin/awk -f
Of course you can always write a script to launch the application:
#!/bin/sh
exec java xxxx $@
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
hvt - 23 Feb 2007 10:30 GMT
On Feb 23, 3:09 pm, LC's No-Spam Newsreading account
<nos...@mi.iasf.cnr.it> wrote:
> So far I've always compiled my application with
> javac xxxx.java
[quoted text clipped - 20 lines]
> avoid unwanted spam. Any mail returning to this address will be rejected.
> Users can disclose their e-mail address in the article if they wish so.
Though I assume (sure basically) that the only way to run a java
program is to invoke it through java command, I am surprised how do
you able to run java program through
java xxxx.class as it should be java xxxx (no .class!!!). IS tht a
typo? :)
Chris Uppal - 23 Feb 2007 15:32 GMT
> Or something like shell or awk scripts, which I could write into files
> with the executable bit set (chmod +x) and prepend with things like
> #!/bin/csh -f
> #! /usr/bin/awk -f
I'm not quite sure what you are looking for but the answer is probably: no, or
at least not easily, and not using only the standard tools.
But if you are looking for a way to use Java to write scripts, then you may
want to look at something like BeanShell:
http://www.beanshell.org/
in particular:
http://www.beanshell.org/manual/execscripts.html#Executable_scripts_under_Unix
-- chris
LC's NoSpam Newsreading account - 23 Feb 2007 17:07 GMT
> I'm not quite sure what you are looking for but the answer is
> probably: no, or at least not easily, and not using only the standard
> tools.
> But if you are looking for a way to use Java to write scripts, then you may
> want to look at something like BeanShell: http://www.beanshell.org/
I've saved the reference, but that's not what I was thinking of. More
the reverse. Invoking an arbitrary java application by name without
prepending the invocation of the java interpreter. Just "xxx" or
"xxx.class" instead of "java xxx" (YES, 'java xxx.class' was a typo).
One suggestion by Gordon Beaton was "Of course you can always write a
script to launch the application:"
#!/bin/sh
exec java xxxx $@
Actually one can do it even with a one-liner script e.g. in our local
environment
#!/scisoft/bin/java myServer
which saves a shell process. Exactly like having a file.awk executable
and prepended with #!/bin/awk -f can invoke it. But this awk file will
contain the code, the one-liner will just make reference to a compiled
myServer.class.
A shell alias (alias myServer 'javac myServer') would be a lighter
solution.
Still is unelegant to have (in principle) search one's path for all
existing .class files and set up aliases for each one. It reminds me of
the old VMS times when I used (at login) to search a path and set up a
logical symbol (I believe was called so) for each program.EXE file in
the path, to avoid invoking a compiled exeutable with "RUN program". I
even had a sort of "rehash" command implied in every compilation.
But I guess I won't have that many java executables around, mainly now
while I'm testing alternatives

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Gordon Beaton - 23 Feb 2007 17:40 GMT
> Invoking an arbitrary java application by name without
> prepending the invocation of the java interpreter.
On Linux, you can use the binfmt misc support to make jarfiles and
class files executable. I remember playing with this about 10 years
ago but haven't thought about it since, and don't know what the
current status is. A quick search came up with this:
http://www.nirendra.net/cms/java/linux
> One suggestion by Gordon Beaton was "Of course you can always write a
> script to launch the application:"
[quoted text clipped - 7 lines]
>
> which saves a shell process.
There is no real difference here. By specifying "exec" the shell
process only exists a short time; exec causes it to be replaced by the
java process.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
LC's NoSpam Newsreading account - 27 Feb 2007 13:28 GMT
> On Linux, you can use the binfmt misc support to make jarfiles and
> class files executable. I remember playing with this about 10 years
Thank you for letting me know about "binfmt". I was not aware of it, but
looks quite interesting.
> > #!/bin/sh
> > exec java xxxx $@
> > #!/scisoft/bin/java myServer
> There is no real difference here. By specifying "exec" the shell
> process only exists a short time; exec causes it to be replaced by the
> java process.
Yes, I know what exec (and the execvp and alike library calls do), but
my friend William of Ockham taught me that shells non sunt multiplicanda
praeter necessitatem :-)

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Andrew Thompson - 23 Feb 2007 17:05 GMT
On Feb 23, 9:09 pm, LC's No-Spam Newsreading account
<nos...@mi.iasf.cnr.it> wrote:
..
> I wonder if there could be a way to invoke the application directly.
I usually find it easier to double click
a jar with manifest that names the main()
class, or open the desktop shortcut/menu
item that web start sets up.
Note though, the first way might require
special set-up on Linux systems (it is
automatic in later Plug-Ins for Windows)
while the second is really only suited to
applications with a GUI.
Andrew T.