LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How can I write a simple script to automatically run a java app? (http://www.linuxquestions.org/questions/programming-9/how-can-i-write-a-simple-script-to-automatically-run-a-java-app-4175448634/)

Brianlicorice 02-04-2013 11:24 PM

How can I write a simple script to automatically run a java app?
 
hi guys, I need to write a script to run a java app automatically, all command lines should be included in the script. Necessary arguments like jdk location and output path are also needed. I've no experience of shell script, can anybody give a simple example for this? no 3rd party libraries.
Thanks!

rigor 02-05-2013 01:11 AM

Is the java app a single class file, or multiple class files?

If multiple files, will they all be in a single directory? OR, are you willing to package them in a single .JAR file?

In general, you can define a "variable" in a bash script, with a statement such as:

Code:

export VARIABLE_NAME=VARIABLE_VALUE
so on my system for example, I'd have:

Code:

export JDK_HOME=/usr/lib64/jvm/java
for the location of the JDK.

Then that could be followed by the command line for the java command, much as you'd type it, if you were manually trying to run the app from the command line.

But the specifics, such as mentioned towards the beginning of this message, can impact exactly what else might be needed in the script. Also, the exact situation/environment from which you intend to run the script, may affect what else might be needed in the script. Because in some situations, things which might be taken for granted in the environment which is present from the command line, might not normally be present, if the script is to be run from some automated facility in the "background". Additional details from you, could be quite helpful in order to answer your question as fully as possible.

Brianlicorice 02-05-2013 01:21 AM

[QUOTE=rigor;4884593]Is the java app a single class file, or multiple class files?

If multiple files, will they all be in a single directory? OR, are you willing to package them in a single .JAR file?
QUOTE]

It's a single file and I'd like to make it a jar. I will need to pass an argument(which is the output path) for the main() using command line and setting up all other arguments. Please give me an example, I never did any shell script.


All times are GMT -5. The time now is 11:10 AM.