I have a java application I copied over from Windows to Ubuntu 18.04. The two important directories are ./bin and ./lib. In ./bin the tree is:

└── com
    ├── google
    │   └── protobuf
    ├── program
    │   └── d1
    │       ├── d1a
    │       ├── d1b
    │       ├── d1c
    │       ├── d1d
    │       ├── d1e
    │       └── d1f
    └── mycompany
        ├── d1
        │   └── d1a
        └── myapp

The Main.class file exists in ./bin/com/program/d1 (./bin/com/program/d1/Main.class) and there is a set of needed jar files in a ./lib folder.

When I use the following command I get Error: Could not find or load main class bin.com.program.d1.Main and I cannot figure out why. The command is:

java -cp ./bin:./lib bin.com.program.d1.Main

I have tried ./lib/* and lib and lib/* etc. Can someone please tell me what I am doing wrong?

TIA, Doug

1 Answer 1


The package name doesn’t include bin, and you need to list the JARs on the classpath:

for jar in lib/*.jar; do CLASSPATH="$CLASSPATH:$jar"; done
java com.program.d1.Main
  • thank you very much as this was a great suggestion. Unfortunately it still gives me the same error. When I compile this mess that works fine, no complaints. I used javac -target 1.8 -source 1.8 -cp "lib/*:" -sourcepath src/ -d bin src/com/program/d1/*,java src/com/google/protobuf/*.java src/com/mycompany/di/d1a/*.java src/com/myapp/*.java Aug 12, 2021 at 15:06
  • You get the “Error: Could not find or load main class bin.com.program.d1.Main” error again? That one exactly? Aug 12, 2021 at 15:27
  • Yes, that one exactly! Aug 17, 2021 at 21:12
  • OK, that means you’re not running the java command in my answer. You need to drop the bin. part of the package name. Aug 18, 2021 at 6:19
  • You were correct, I screwed up the command. It tries to start now. The other issues are on my side. Thank you! Aug 23, 2021 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .