You know when the whole aspect of having so many IDEs to help you do things like compile and running of your code, yeah i was biten in the a** of late and was expect to provide a jar file needed to be executed by someone else but i needed to test the jar which has other jar dependence through a commandline. I knew I had to add the jar dependencies as parameters to the java
binary, but I was unsure how to do that. After a bit of googling
around , I found out how to achieve this. Here’s a skeleton :
java -classpath lib1.jar;lib2.jar package.otherpackage.classname argv1 argv2 ... argvn
If you have your .class files in a folder, let’s say the name of the folder is classes, then you need to add that folder to the classpath, so the skeleton becomes :
java -classpath classes;lib1.jar ...
I hope you get the picture. If you don’t know what jars to include, but your project works in eclipse, you can open the .classpath file and extract the entries with kind=”lib”. Here is a sample .classpath file from a project :
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
<classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="lib/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
You can easily parse this file and extract them. This was how i got through the task.
Hope this helps someone.