Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running .jar file within JSP page

Tags:

java

jsp

jar

I'm trying to develop a website that takes user input and converts to a text file. The text file is then used as an input for a .jar file. (e.g. java -jar encoder.jar -i text.txt), the jar then outputs a .bin file for the user to download.

This jar is designed to be run from command line and I really don't know the best way to implement it within a .jsp page. I have created a few java test classes but nothing has worked so far.

Does anyone have any suggestions on possible methods?

like image 646
Bam421 Avatar asked Nov 18 '12 15:11

Bam421


1 Answers

An alternative to running it as an external process is to invoke its main class in the current JVM:

  1. Extract/open META-INF/MANIFEST.MF of the jar
  2. Identify the Main-Class:. Say it is called EncoderMainClass
  3. Invoke its main method: EncoderMainClass.main("-i", "text.txt")

This aught to be faster because a new OS process does not need to be created, but there may be security considerations.

like image 75
Miserable Variable Avatar answered Oct 27 '22 00:10

Miserable Variable