aspose file tools*
The moose likes Beginning Java and the fly likes how to invoke a java program using shellscript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to invoke a java program using shellscript" Watch "how to invoke a java program using shellscript" New topic
Author

how to invoke a java program using shellscript

guestin loy
Greenhorn

Joined: Oct 09, 2008
Posts: 5
Hi,

How can i exceute a java program using shellscript.
tried like :
#!bin/sh
path/to/java test.java


but its not invoking the program.

could you please suggest me on this?

Regards.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

don't you want the name of the class - not the name of the java file?

#!bin/sh
path/to/java test


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
"java" is the interpreter, not the compiler. It takes a class name as parameter, not a source file.


Ping & DNS - my free Android networking tools app
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
And it should be #!/bin/sh.


SCJP 5.0, SCJD in progress
guestin loy
Greenhorn

Joined: Oct 09, 2008
Posts: 5
i tried by giving class name also. but it is still not invoking that.

#!/bin/sh
path/to/java test


its giving error as :
path/to/java: not found

could you suggest on this?
Regards.
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
If java is properly installed on your system, it should suffice to only type 'java'. You can check this by typing 'java -version'. If you receive some information about your JVM you're fine. Otherwise, check whether your 'path/to/java' is actaually a path to the java binary. If so, it usually looks something like 'path_to_java_install_dir/bin/java'.
[ October 15, 2008: Message edited by: Thomas Thevis ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Forget about the shell script - what works on the command line? if it works on the command line, it should work in the script.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to invoke a java program using shellscript