Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to invoke a java program using shellscript

 
guestin loy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12181
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't you want the name of the class - not the name of the java file?

#!bin/sh
path/to/java test
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java" is the interpreter, not the compiler. It takes a class name as parameter, not a source file.
 
Thomas Thevis
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it should be #!/bin/sh.
 
guestin loy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12181
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about the shell script - what works on the command line? if it works on the command line, it should work in the script.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic