0

Possible duplicate "How to run Unix shell script from Java code?".

I would like to know how to execute java code using shell script?

I want to know is :

shell script executes java code.

I don't want to know is

java code executes shell script.
  • My OS version is cent0s 5.5 (64-bit).
3
  • You need to fire up the compiler and then run the JVM. Is this what you want? Commented Oct 6, 2012 at 3:50
  • Simple java -jar your_jar.jar or javac your_class would work. or you mean something else? Commented Oct 6, 2012 at 3:53
  • @nhahtdh Yes, I want to run .sh file and these file run java program. Commented Oct 6, 2012 at 3:54

1 Answer 1

2

As in, like this you mean?

#!/bin/sh
java -jar your-java-compiled-into-a.jar
Sign up to request clarification or add additional context in comments.

4 Comments

According to your answer, do i need to compile java class?
Yes, the JVM can only run bytecode (.class files). You can pack it into a Jar like Tom said.
If you don't want to compile but still use the JVM you need to avoid java and use one of the scripting languages that can run on the JVM such as ruby (jruby), javascript (rhino), groovy...
If you don't have a jar, just do java Foo to execute Foo.class

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.