I am facing a problem in running a jar file from my servlet.
I have to run a jar file of another java application with arguments in a separate sevlet in web project in Eclipse.
I use the code as
Runtime.getRuntime().exec("java -jar myproject.jar param1 param2 abc.xml");
In above code, on running the above jar file with parameters param1 and param2 , it will store output in abc.xml.
But the problem is that i dont know how to give the path of myproject.jar in code.
I copied myproject.jar to the project directory and it does not give any output.
I have tried to use
I dont know how to give path of jar file and where to put the jar file and where the out put file will come .
This code works fine with simple core java application where i put my myproject.jar file in the core java project directory and the output file abc.xml is created in the core java project directory.
Please guide me.
Thanks in advance.
This is not the right way of invoking Java code contained in some JAR in the classpath (I assume that you have placed it in
/WEB-INF/lib). Just import and invoke the code contained in that JAR file directly.Or if that API is well designed, then just use its entry classes directly instead of calling a
main()method.