invoking a java application by name

G

Guest

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
 
G

Gordon Beaton

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
 
H

hvt

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

--

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? :)
 
C

Chris Uppal

LC's No-Spam Newsreading account said:
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
 
A

Andrew Thompson

On Feb 23, 9:09 pm, LC's No-Spam Newsreading account
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.
 
G

Guest

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
 
G

Gordon Beaton

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:"
#!/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.

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
 
G

Guest

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.

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top