0

This same Java class will compile from the command line, but not from NetBeans. Here is the .java file contents:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ripplesoftware.sitereviewer;

import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.core.QTextCodec;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QMainWindow;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QTabWidget;

/**
 *
 * @author development
 */
public class siteReviewer {

    public static void main(String[] args){
      QApplication.initialize(args);
      QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8"));
      QTextCodec.setCodecForLocale(QTextCodec.codecForName("UTF-8"));

      QMainWindow mainWindow = new QMainWindow();
      /* Set main window */
      mainWindow.setWindowTitle("RSC Site Reviewer");
      mainWindow.setFixedSize(600,800);
      mainWindow.setVisible(true);
      /* Set Layout */
      QVBoxLayout vBoxLayout = new QVBoxLayout();
      vBoxLayout.setContentsMargins(0, 0, 0, 0);
      QWidget mainWidget = new QWidget();
      mainWidget.setFixedSize(600,800);
      mainWidget.setVisible(true);
      mainWidget.setLayout(vBoxLayout);
      mainWindow.setCentralWidget(mainWidget);
      /*  */
      /* Setup tab */
      QTabWidget tabWidget = new QTabWidget(mainWidget);
      tabWidget.setDocumentMode(false);
      QWidget tab = new QWidget();
      tabWidget.addTab(tab, "Tab 1 with lots of words");
      QWidget tab2 = new QWidget();
      tabWidget.addTab(tab2, "Tab 2");

      QPushButton hello = new QPushButton("Quit");
      hello.resize(120, 40);
      hello.show();
      vBoxLayout.addWidget(hello);

      QApplication.execStatic();

    }

}

Here is how I compile from command line:

$ javac -cp qtjambi-4.8.6.jar:qtjambi-native-macosx-gcc-4.8.6.jar siteReviewer.java
$ java -XstartOnFirstThread -cp qtjambi-4.8.6.jar:qtjambi-native-macosx-gcc-4.8.6.jar siteReviewer.java

Works fine and windows pops up with expected components.

However, when compiling same code with NetBeans Maven Project:

--- exec-maven-plugin:3.0.0:exec (default-cli) @ SiteReviewer ---
Error: Unable to initialize main class com.ripplesoftware.sitereviewer.siteReviewerApp
Caused by: java.lang.NoClassDefFoundError: com/trolltech/qt/gui/QLayout
Command execution failed.

Here is the pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ripplesoftware</groupId>
    <artifactId>SiteReviewer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.trolltech.qt</groupId>
            <artifactId>qtjambi</artifactId>
            <version>4.8.6</version>
            <scope>system</scope>
            <systemPath>/Users/${USER}/.m2/dependencies/qtjambi-4.8.6.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.trolltech.qt</groupId>
            <artifactId>qtjambi-native-macosx-gcc</artifactId>
            <version>4.8.6</version>
            <scope>system</scope>
            <systemPath>/Users/${USER}/.m2/dependencies/qtjambi-native-macosx-gcc-4.8.6.jar</systemPath>
        </dependency>
    </dependencies>
</project>

I'm confused because I'm not calling a class QLayout, and the code compiles fine from command line. I believe the import statements are OK, because it was preivously complaining about the import com.trolltech.qt was not found.

raw-bin hood
  • 5,839
  • 6
  • 31
  • 45
  • maybe OT, but you have to follow convention, in java the first letter of the class name have to be uppercase – Alberto Sinigaglia Jun 09 '21 at 18:10
  • Does this answer your question? [Netbeans - Error: Could not find or load main class](https://stackoverflow.com/questions/20034377/netbeans-error-could-not-find-or-load-main-class) – Alberto Sinigaglia Jun 09 '21 at 18:11
  • Don’t use systempath. – Thorbjørn Ravn Andersen Jun 09 '21 at 18:43
  • I'm new to Java and I found that NetBeans makes things much too complicated. I don't understand what systempath is. I don't know how to specify the location of the .jar files without systempath. – raw-bin hood Jun 09 '21 at 19:08
  • 1
    Check this to avoid usage of systempath https://stackoverflow.com/a/31023523/6813506. You are getting java.lang.NoClassDefFoundError for com.trolltech.qt.gui.QLayout which you are not calling directly But, it is required at Runtime as a transitive dependency. In Simple java program the QLayout class is available in cp as qtjambi-4.8.6.jar So its working. – Rohit Gaikwad Jun 09 '21 at 19:29

0 Answers0