4

Possible Duplicate:
Execute another jar in a java program

I have an executable jar file that accepts two parameters: an input file and an output file:

java -jar inputFile.txt outputFile.txt

How can I call exactly this from JavaScript?

4
  • 5
    I'm hoping you understand the complete and utter difference between Java and JavaScript. Are you building a website or web application? Commented Aug 6, 2012 at 4:00
  • I've edited the question so that it makes some sense. If you don't find the edits appropriate, please roll them back. Commented Aug 6, 2012 at 4:08
  • 1
    stackoverflow.com/questions/1320476/… Commented Aug 6, 2012 at 4:09
  • @Blender: That changes the meaning of the question. The original was about how to call it from JavaScript, not Java, which is a perfectly reasonable (if uncommon) thing to do. Commented Aug 6, 2012 at 4:40

2 Answers 2

6

The answer depends on the context.

  • If your javascript is running in a web browser sandbox, then the answer is that you can't run a JAR file. The sandbox is designed to stop you doing that kind of thing.

  • If your javascript is running under node.js, then this SO Q&A offers a solution to the problem of running a command: How do I run the system commands in javascript?. This can be used to run the java command with the appropriate args.

  • If your javascript is trusted code running in a browser with a Java plugin, then you may be able to make a call to java.lang.System.exec(...) passing an appropriate java command line in the appropriate fashion. You may also be able to create a classloader, read the JAR file's manifest, extract the entry point class, load it, and call the "main" method.

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

Comments

-5
java -jar executable.jar inputFile.txt outputFile.txt

For further details see the java command synopsis:

SYNOPSIS

  • java [ options ] class [ argument ... ]
  • java [ options ] -jar file.jar [ argument ... ]
  • javaw [ options ] class [ argument ... ]
  • javaw [ options ] -jar file.jar [ argument ... ]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.