I have seen this question asked so many times, but there was no precise answer to my problem. My story is simple - I downloaded a legitimate JAR file, for a functioning and advertised application, from here: https://github.com/kamilfb/mqtt-spy/wiki/Downloads.
The application brings the obvious instruction to start it as java -jar mqtt-spy-0.2.0-jar-with-dependencies.jar
but that results in the well known error, being in my case Error: Could not find or load main class pl.baczkowicz.mqttspy.Main
My system is Ubuntu 15.04, Java version is
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
I don't have another computer to test it elsewhere. I did some checks and the JAR file looks pretty much normal. I even tried de-compressing it and running the class directly, it won't budge, same error message. I tried some online .class analysis tools, nothing caught my attention. Also I reviewed about a dozen of pages referring to "Could not find or load" problem. No luck so far.
Not sure if anyone bothers, but I did my Java Programmers certification with Sun yet in 2005... and I feel frustrated now. While I hope there is an easy solution for my problem, e.g. some nice Ubuntu issue ;-), I am ready to dig deeper, and looking for any hints that would guide me to finding the root cause of this issue.
Thank you it was very helpful for me. I had exactly the same problem, and looking the solution here as well
My fix was:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
then, install the JDK Oracle 8
sudo apt-get install oracle-java8-installer
and then, checking java:
sudo update-alternatives --config java
It is displayed between other choices:
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1082
auto mode
......
Press to keep the current choice[*]
, or type selection number:
I keep the 0 current choice [*]
then, running mqttspy worked just fine :-)
java -jar mqtt-spy-0.5.1-jar-with-dependencies.jar