mahmood
mahmood

Reputation: 24715

Could not find or load main class, but .class exists

I want to compile a bunch of .java files with a library .jar file. Following this topic, my previous GUI program runs fine. However, this command line program fails!

$ /opt/jdk1.8.0_131/bin/javac -classpath lib/*.jar *.java
$ ls
Module1.class  Cross.class  Ora.java  Safe.class
Module1.java   Cross.java   p1/       Safe.java
lib/           Ora.class      
$ grep main Module1.java
   public static void main(String[] args) {
$ ls lib
jsoup-1.10.3.jar
$ /opt/jdk1.8.0_131/bin/java -classpath .:lib/* Module1
Error: Could not find or load main class Module1

How can I fix that?

Upvotes: 0

Views: 1365

Answers (1)

Steve Bauer
Steve Bauer

Reputation: 179

Does Module1.java have no package statement? If there is a package statement then it would need to be moved into the package folder and run with a command like

/opt/jdk1.8.0_131/bin/java -classpath .:lib/* package.Module1

I didn't know classpath would support wildcards but looks like that added that in java 6 which shows how long since I have run java from the command line.

Add the body of Module1.java to your question if you are not sure what I am asking.

Upvotes: 1

Related Questions