Aaron Aaron - 11 months ago 54
Java Question

How will I include a Java jar file when compiling a Java class and running the Java file from the command console?

I have a small Java file interacting with a postgresql database,
so I've downloaded the drivers and in my file I import


In the command console I type
javac Myfilename.java
then it compiles I run
java Myfilename
and it throws an error saying it can not find the

So how do I import the jar when I run the file or when I compile the file not sure when the import should take place?

Answer Source


javac -cp ".:postresql.jar" -d . MyFileName.java


java -cp ".:postresql.jar" MyFileName