I have a command line application which I need to reference from another jar file and what I don’t want to do is copy and paste the existing code into the project that contains the source files for the other application, since this approach will result in maintainability issues.
I have thought about doing the following:
-
deploying 2 jar files; running the command line app as a Process (the problem with this approach is that I don’t want to deal with orphan processes).
-
deploying 2 jar files; calling the main method of the command line app using reflection. (I’m not sure this is a good idea).
-
Somehow referencing the project that contains the source code for the command line application, and write an ant file that copies the class files into the jar file for the other application.
Which of this approach makes most sense? if the answer is #3, how exactly do I need to set up the eclipse project and/or write the ant file such that the class files I need are included in the new jar file?
In my opinion, I am more inclined to Approach 1.
Assume your command line application is Jar1 and the referenced 3rd party jar is JAR2. Just add JAR2 to classpath. That’s it. You can invoke all the desired classes from Jar1. Since it’s a command line application and you don’t want to deal with orphan process, the ideal way to handle with it is, you should handle it from your command line application to kill orphan process, similar to what you do from your finally block of try-catch.
I am disoriented towards your Approach 2 as reflection is very discouraged/outdated as it gets very difficult to debug in case of any issues