I have a couple of Java files A.java and B.java that use a common jar file C.jar. B.java contains reference variables to the object of type A. B.java contains the main method
I compiled using the following command.
javac -cp C.jar A.java B.java
It compiles.
However, when I run it says main method not found.
I ran
java -cp C.jar B
Am I making some mistake in my commands?
Am I making some mistake in my commands?
Yes - you're not including anything apart from C.jar
when trying to run.
Use
java -cp C.jar;. // Windows
java -cp C.jar:. // Unix
So that you're including the current directory (which is where A.class
and B.class
are, presumably) on the classpath.
See more on this question at Stackoverflow