How to compile Java program with .jar library
javac -cp <jar you want to include>;<jar you want to include> <source.java>
<jar you want to include>
if in same directory, just name of jar will do, if not, specify full or relative paths
if more than one jars, separate with ,
replace ;
with :
on unix
If possible, use some IDE like Eclipse. I used to spend a lot of time on similar things, but in industry, you will hardly ever do it in this fashion.
Check list:
your classes in acm.jar appear as:
acm/program/CLASSX.class
acm/program/CLASSY.class
when decanted with jar tf acm.jar
You're importing them like:
import acm.program.CLASSX ;
or
import acm.program.* ;
Are you running these commands on a Windows machine? On Windows, the elements of the classpath are separated by a semicolon, not a colon. So:
javac -classpath .;acm.jar TestConsole.java
Another possibility: the structure of acm.jar
is wrong. It's not sufficient that the class files inside were compiled from files that declare package acm.program
- the package structure must also be represented as a directory hierarchy, so acm.jar
must contain a directory acm
, and within that a subdirectory program
that contains the actual class files for the classes used in TestConsole
.