2

I'm trying to compile and run the tooltip code from this tutorial. I obtained QtJambi from my package manager (the package is qtjambi-beta from AUR), which installed it into the directory /opt/qtjambi-beta/. In particular, the qtjambi-4.7.0.jar file is located at /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar.

Now, I made a folder called qtpractice and put the example in there under the name JambiApp.java. The code I put into it was exactly as follows (following the example I linked):

package qtpractice;

import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QWidget;

public class JambiApp extends QWidget {

     public JambiApp() {
        setWindowTitle("Tooltip");
        setToolTip("This is QWidget");
        resize(250, 150);
        move(300, 300);
        show();
    }


    public static void main(String args[]){
        QApplication.initialize(args);
        new JambiApp();
        QApplication.exec();
    }
}

I compiled it with javac qtpractice/*.java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar, which worked fine. I then tried to execute it with java qtpractice.JambiApp, and I got the following error:

Error: Could not find or load main class qtpractice.JambiApp

EDIT: Based on some advice from the comments, I tried this command instead: java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar qtpractice.JambiApp . When I did this, I got the following error again:

Error: Could not find or load main class qtpractice.JambiApp

What did I miss? From what I can tell, I did everything necessary to make it execute.

Smar
  • 8,109
  • 3
  • 36
  • 48
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
  • You need to give same `-cp` args to `java` command too. That’s common Java practice. – Smar Sep 30 '14 at 08:09
  • @Smar: Tried that - same error exactly. – Koz Ross Sep 30 '14 at 08:12
  • Please add the whole command line and error to your question. – Smar Sep 30 '14 at 08:14
  • You need to add the native jar to execution command too (it’s not required for compilation). – Smar Sep 30 '14 at 08:26
  • @Smar: What do you mean by the 'native jar'? – Koz Ross Sep 30 '14 at 08:28
  • There should be jar which name is `qtjambi-native-linux64-gcc-4.8.6.jar` or similar, or something with `linux32` `linux64`, depending of how old that version is. Could you give name of that jar so I could make proper answer? :) – Smar Sep 30 '14 at 08:40
  • @Smar It is ``qtjambi-linux64-gcc-4.7.0.jar``. – Koz Ross Sep 30 '14 at 09:55
  • Okay, answered. Sorry for late response, I was at work and forgot about the question :) I hope the thing worked for you though. – Smar Sep 30 '14 at 15:03

1 Answers1

1

You need to include all jars Qt Jambi needs in classpath.

This can be done on CLI with command similar to

java -cp /opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-4.7.0.jar:/opt/qtjambi-beta/qtjambi-linux64-community-4.7.0/qtjambi-linux64-gcc-4.7.0.jar:. qtpractice.JambiApp

When compiling, native jar does not need to be present, as the native libraries are just for Jambi classes to be able to use Qt.

Smar
  • 8,109
  • 3
  • 36
  • 48
  • Also a further note - I tried doing this in Eclipse, and it worked fine. However, I don't really want to use an IDE (and I don't get how it does all this stuff anyway), and this has me really mystified, so I'd like to figure out what the hell is going on. – Koz Ross Oct 01 '14 at 00:20
  • Well, then give the full error (what the command returned when you ran it) – Smar Oct 01 '14 at 07:28
  • ``Error: Could not find or load main class qtpractice.JambiApp`` – Koz Ross Oct 01 '14 at 08:08
  • that’s *all* it returned? – Smar Oct 01 '14 at 10:37
  • I'm as mystified as you are. – Koz Ross Oct 01 '14 at 10:50
  • Ohh... I think I got it. When you’re running with classpath, current directory is not in classpath by default. So if the class you’re running the file from current directory, you need to add :. to end of the classpath. I’ll update the answer. – Smar Oct 01 '14 at 11:17