Showing posts with label jar. Show all posts
Showing posts with label jar. Show all posts

Sunday, December 12, 2010

Dealing with external jar files on command prompt

I had a problem with compiling and running a java file in command line where it imports an external jar files. Here is the solution I've found.

Compilation

javac -cp <path to where the source codes resides>;<path to where the jar file resides> Example.java

run

java <path to where the source codes resides>;<path to where the jar file resides> Example <command-line arguments if any>

Note 1:  separator ; for windows and : for unix
Note 2:  multiple jar files can be used delimited by ;
Note 3:  . can be used to specify the current directory

How to run a jar file with command line arguments

  1. Open up a command prompt.
  2. Go to the directory which jar file resides using the command "cd".
  3. Type the following command to execute jar file with command line arguments.
    • java -jar <name of the jar file> <command line argument1> <command line argument2>


Thursday, November 11, 2010

How to add external jar files in eclipse

1. Inside the "package explorer", Right click on the project which needs to add the external jar file and click on "properties".


2. In "java build path", inside "Libraries" tab choose the external jar file by clicking on "Add external JARs" button and click "OK".