Similar question has been asked several times before but none helped me. Please provide solution.
This works fine in eclipse but I am unable to run it in cmd(Windows)
I have created an jar file with few classes which have some static methods (no main class inside jar) and I want to import it on an java file(which have main()
) and run it.
It compiles successfully but while executing it gives error
could not find or load main class test
both jar file and java file are inside same directory
to compile I am doing
javac -cp file.jar test.java
to execute
java -cp file.jar test
I have tried followings while searching different answers but none worked:
java -cp file.jar:. test
java -cp .:file.jar test
Please guide me what I am doing wrong.
Here's test.java:
import pkg.classname;
class test {
public static void main(String[] args) {
...
}
}
Here's the output of jar tf
:
$ jar tf file.jar
META-INF/MANIFEST.MF
pkg/classname.class
pkg/others.class
PS:I intentionally tried giving invalid jar file name but the error is same.