javajspjar

Running JAR file on the JSP page


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 an 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 an JSP page. I have created a few Java test classes, but nothing has worked so far.

Does anyone have any suggestions on possible methods?


Solution

  • 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.