Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Beginning Java and the fly likes call java program from script? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "call java program from script?" Watch "call java program from script?" New topic

call java program from script?

david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
I am a linux newbie but I want to call java program from a shell script

it is a bash shell and is it also possible to pass variables to the java program when it is called?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Sure., Just run the program as "java ClassName arg1 arg2 ...", where ClassName is the name of the main class, and arg1, etc, are the command-line arguments to the program. There are, of course, class path issues, etc, but this is the basic idea.

[Jess in Action][AskingGoodQuestions]
Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
You can also launch a jar file, provided it has a manifest that points to the class where the main method is:

Have you tried LearnNowOnline?
subject: call java program from script?