2

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.

  • Possible duplicate: [What does “Could not find or load main class” mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean). – Pshemo Aug 16 '15 at 22:58
  • 1
    Anyway lets start from beginning. Did you check MANIFEST in the JAR file? Which class does it point as main-class? Based on error message it may look like it is `pl.baczkowicz.mqttspy.Main`. Does your Jar contain `pl/baczkowicz/mqttspy/Main.class` structure? – Pshemo Aug 16 '15 at 22:58
  • 1
    I've downloaded the latest version (0.2.0) and works with no problems in my machine. Using HotSpot 1.8.0_45. – Luiggi Mendoza Aug 16 '15 at 23:00
  • Luiggi - thanks! At least that gives me some hope :) Pshemo - In manifest: Main-Class: pl.baczkowicz.mqttspy.Main, after unpacking the jar i get to see the class file is there: `nathan@nthlx:~/mqtt-spy$ ls pl/baczkowicz/mqttspy/ application.css connectivity logger scripts tasks utils common events Main.class stats testcases versions configuration exceptions messages storage ui xml` – Marcin Gałczyński Aug 16 '15 at 23:06
  • After Luiggi's comment if you wouldn't have this structure and manifest it would simply mean you didn't download same file. Actually maybe it is worth checking if your file is not corrupted, so that Main.class couldn't be loaded properly. Did you try redownloading this jar, or downloading it from different location? – Pshemo Aug 16 '15 at 23:13
  • Thanks for the advice. I downloaded the file using another link (there are 2 distinct on the page) and I get the same result. Also, if my download would be corrupted, I would probably get an error while extracting the contents of JAR file. – Marcin Gałczyński Aug 16 '15 at 23:15
  • For all the friendly people out there - Yes, I have also tried re-booting my computer ;) – Marcin Gałczyński Aug 16 '15 at 23:17
  • Damn it. That was my next question https://www.youtube.com/watch?v=p85xwZ_OLX0. Anyway since I am not working on Ubuntu and don't have it installed I can't help you more with testing what went wrong. Sorry. For now try using `java -cp yourJar pl.baczkowicz.mqttspy.Main` and see if it helps. – Pshemo Aug 16 '15 at 23:18
  • I have tried this option already. Thanks – Marcin Gałczyński Aug 16 '15 at 23:24

4 Answers4

4

Additionally install Java FX, since this is required and worked for me (Ubuntu 16: package openfx):

apt install openjfx

See also this issue: https://github.com/kamilfb/mqtt-spy/issues/88

I currently successfully run it on openjdk version "1.8.0_121" here.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
MoreIT
  • 73
  • 3
  • installing `openjfx` fixed this problem with proper version of java installed in advance – MiroO Jan 22 '18 at 16:36
2

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
NSNoob
  • 5,548
  • 6
  • 41
  • 54
Ines
  • 36
  • 2
1

The solution that worked in my case was to use HotSpot Java 8, from Oracle.

0

Just in case you have multiple java versions, you can run the jar file by giving the java file path as well.

brew install --cask liberica-jdk@17-full
brew install --cask liberica-jdk17-full
/Library/Java/JavaVirtualMachines/liberica-jdk-17-full.jdk/Contents/Home/bin/java -jar mqtt-spy-1.0.1-beta-b18-jar-with-dependencies.jar