1

I have a weird problem: Netbeans is not recognizing a JAR file added as a library.

I used to have classes in the default package and I was able to access Thing.jar by calling new Thing(); in the Main class. After I created some packages and reorganized my classes, Netbeans started complaining over that line of code: "cannot find symbol: Class Thing". I tried removing/adding the jar library. It doesn't complain anything and I can see the jar file under projects/libraries. Google also didn't turn up any magic tricks regarding how to add JAR files. I don't understand why this worked inside the default package, but doesn't work in another package.

Atte Juvonen
  • 4,922
  • 7
  • 46
  • 89

2 Answers2

0

Have you imported the classes at the beginning of your file. If a class is not in the same package java requires an import, even when the jar file is placed in the Libraries.

0

You shouldn't use the default package if you want the class to be available outside the current jar. It is not possible to import from the default package.

See How to import a class from default package

Community
  • 1
  • 1
bradimus
  • 2,472
  • 1
  • 16
  • 23
  • I didn't create the JAR file, I just have to use it. – Atte Juvonen Feb 22 '16 at 14:35
  • 1
    I understand the situation as this: (1) You need to import a class from the default package. (2) It is a compile time error to import from the default package. I don't think there is much we can do t help you. – bradimus Feb 22 '16 at 14:50
  • I chose to decompile the JAR. It appears to be working. Thanks for the link. – Atte Juvonen Feb 22 '16 at 14:54