Running .jar file on JSP page

I am trying to develop a website that introduces the user and converts him to a text file. The text file is then used as input for the .jar file. (e.g. java -jar encoder.jar -i text.txt ), jar then prints the .bin file for the user to download.

This jar is designed to be run from the command line, and I really don’t know how best to implement it on the .jsp page. I have created several Java test classes, but so far nothing has worked.

Does anyone have any suggestions regarding possible methods?

+6
source share
3 answers

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

  • Extract / open the META-INF/MANIFEST.MF flag
  • Define Main-Class: Let's say it's called EncoderMainClass
  • Call main : EncoderMainClass.main("-i", "text.txt")

This should be faster because the new OS process does not need to be created, but security concerns may arise.

+3
source

Have you tried something like this,

Create java file

use ProcessBuilder and run the new JVM.

Here's what you need to get started:

 ProcessBuilder pb = new ProcessBuilder("/path/to/java", "-jar", "your.jar", "thetextfile.txt"); pb.directory(new File("preferred/working/directory")); Process p = pb.start(); 

ps: do a pen to kill the process, otherwise it will consume all the memory

0
source

You can put this jar in a web application along the classpath path and use its class and methods. Better if you have javadoc if you have no sources. But even if not in the classpath , you can try an example or this example .

0
source

All Articles