I had a requirement to create a small file utility class to run off the command line from a windows desktop. The code got completed, however, after reviewing how to package it, it requires a custom framework from the main application in order to run. Don't ask why as that would take a while to answer, just take this as a valid assumption.
In any event, now they want a jsp to call this class, but they still want it to be more of a separate utility, even though it's part of the main codebase. They also want it to call the main method in the utility, which doesn't sound like good design to me, but they didn't want to change it to a servlet class.
The program just takes in some arguments and then it's basically on one step operation on the files, then it finishes. Not really a jsp type request/response scenario, but I'm not the one writing the requirements.
From a design perspective, is there a better way to do this for a simple utility application?
Thanks,
James
If you really can't change the design, you could either just import the class and invoke it (this works only if it's in the webapp's classpath).
YourMainClass.main(new String[] {"some", "arguments"});
Or spawn a process and execute it (this is really not recommended as the new process would allocate another bunch of memory which is as much as the server is currently using!).
Runtime.getRuntime().exec("java -cp /path/to/root com.example.YourMainClass some arguments");
Both ways can be done in a scriptlet (yuck), or preferably just in a Servlet.