0

I'm new to Java and Netbeans. I'm trying to import a library but all the instructions I've found online either reference a "Library" folder in the Netbeans project, or a "Library" tab when right-clicking the project and selecting "Properties". I'm using Netbeans 12 on MacOs and neither of those exist when I create a new "Java Application" project.

enter image description here

I have the .jar files. I have tried Tools > Library > New Library > Add JAR / Folder, and included the whole directory, but I get this error when trying to Run from NetBeans:

package com.trolltech.qt.gui does not exist

When I include the .jar files them in the base directory of the application and compile from the command line as described below they are imported and the application runs as expected.

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

Here is the code of the app:

package com.me.app;

import com.trolltech.qt.gui.*;

public class App {
    
    public static void main(String[] args){
        QApplication.initialize(args);
        QMessageBox.information(null, "QtJambi", "Hello World!");
        QApplication.shutdown();
        
    } 
    
}

Here are contents of the directory:

    $ ls -lah
total 70608
drwxr-xr-x  7 development  staff   238B  7 Jun 11:08 .
drwxr-xr-x  3 development  staff   102B  7 Jun 08:02 ..
-rw-r--r--  1 development  staff    80K  7 Jun 11:08 hs_err_pid6586.log
-rw-r--r--@ 1 development  staff   3.2M 15 Nov  2014 qtjambi-4.8.6.jar
-rw-r--r--@ 1 development  staff    31M 15 Nov  2014 qtjambi-native-macosx-gcc-4.8.6.jar
-rw-r--r--  1 development  staff   732B  7 Jun 11:08 App.class
-rw-r--r--  1 development  staff   801B  7 Jun 11:08 App.java

How should I import the .jar files into Netbeans 12 for MacOs?

raw-bin hood
  • 5,839
  • 6
  • 31
  • 45
  • In the folder you added, do you have source or compiled files? What format of library do you want to include? – Arcaniaco Jun 07 '21 at 15:08
  • I am new to Java, so I don't know about library format, except they are .jar files. I didn't add a directory, I just added the .jar files to the project directory and it will compile from command line. I will add the directory contents to OP. – raw-bin hood Jun 07 '21 at 15:15
  • Ok. Try do this: In the left box, expand your project and right click on **Libraries > Add JAR / Folder** and add your `.jar` file. I recomend to use some framework to manager your projects dependencies. I use `maven`. [See more](https://maven.apache.org/guides/getting-started/). – Arcaniaco Jun 07 '21 at 16:05
  • As I mentioned in the OP, there is no Library available in the left-panel. Also, I created the project with type Java (Maven). – raw-bin hood Jun 07 '21 at 16:15
  • Are you looking on the project group? When do you expand your project doesn't show the project folders? Source Package, Test Package, Libraries and Test Libraries? Look [this](https://www.tutorialspoint.com/maven/images/nb_project_structure.jpg) common maven project default structure. – Arcaniaco Jun 07 '21 at 16:27
  • I added image to OP. – raw-bin hood Jun 07 '21 at 16:39
  • Okay, install a local dependencie in maven. Look [this](https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project/22300875). – Arcaniaco Jun 07 '21 at 17:40
  • Does this answer your question? [How to add local jar files to a Maven project?](https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project) – skomisa Jun 07 '21 at 23:55
  • 1
    As @HigorMaiaConcessa pointed out, because you created a Maven project (as opposed to an Ant project) NetBeans does not provide a Library node for your project. Instead, add your jar files as `` entries in your **pom.xml** file. There are a lot of (mostly older) tutorials that mention using **Library** because Ant projects were much more prevalent prior to the widespread acceptance of Maven. If you want to use **Library** just create your project using _Java with Ant_ instead. – skomisa Jun 08 '21 at 00:03

0 Answers0