1

I have a jar file with 2 classes class A and class B and each of them has a main method.

I want to create two separate shell scripts to call each one of them. Script 1 for class A and script 2 for class B. In each script I need to do the following:

  1. Call the particular class and pass arguments to its main method args[0]
  2. The passed arguments should be accessible using System.getProperty()
  3. The main method should be able to send back appropriate message to the shell script to display it on the console.

I read on StackOverflow that this can be done by writing the string to stdout with: System.out.println("My message");

My question is how should the shell script command be written for the above java class call?

Currently I was playing around with this and it's not working:

output = $JAVA -classpath "$CLASS_PATH" -jar /location_of_jar/myjar.jar packagenameofmyclass.MyClass -Dusr.dir=$CUR_DIR $input1 $input2 RC=$?
echo "$output"

$JAVA CLASS_PATH CUR_DIR is a variable whose value I have set above in the script file.

Please could someone help me out? Am I even going in the right direction.

1 Answer 1

1

Try:

output=`$JAVA -classpath "$CLASS_PATH" -jar /location_of_jar/myjar.jar packagenameofmyclass.MyClass -Dusr.dir=$CUR_DIR $input1 $input2`

The ` marks should make it execute.

Sign up to request clarification or add additional context in comments.

1 Comment

The preferred and more portable way is to use $( java...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.