Search code examples
javanetbeansjarnullpointerexceptionclassnotfoundexception

Java trying to find 3rd party class in my package even though that class is in an included JAR


I'm new to Java and NetBeans and I'm having a very hard time getting a simple project started.

I'm trying to include .jar files I need to work on a NetBeans plugin. I can successfully add the .jar files to my project using a variety of attempted methods.

  • I added .jar files by the project properties and added the 'wrapped jar' files to the project
  • I added the .jar files to the 'Libraries' item in the Projects explorer tree

Both methods appear to work in the IDE. They allow the desired classes to be accessed in the IDE and no syntax or access errors (etc) are detected. However, when I build and run I get ten pages of errors such as NullPointerException and this doozy:

java.lang.ClassNotFoundException: Will not load class org.netbeans.modules.openide.nodes.NodesRegistrationSupport arbitrarily from one of ModuleCL@2afef4c1[org.openide.nodes] and ModuleCL@2debe24[com.myproject.simplelauncherbutton] starting from SystemClassLoader[316 modules]

com.myproject.simplelauncherbutton is my own package. Why would NetBeans even be looking in my package for this class? And even if it is looking there, how can it be finding the class there, to be confused? I just want to make a NetBeans plugin using a .jar file for support. How can I get this working?!


Solution

  • Solved with help from a coworker. The problem was the way in which I was including packages in my project. I was trying to include packages in my project that did not seem to be available. For example, I needed to use org.openide.nodes, so at the top of my class file I wrote:

    import org.openide.nodes;
    

    NetBeans would respond saying it couldn't find this package. When I found a wrapped JAR package containing org.openide.nodes and included that in my project, it generated a slew of errors too long to list here.

    However, when I add the module by its English name "Nodes API" in the project properties, everything works fine. I wish there were some documentation or instructions I had been able to find to save me hours of stressing about why I couldn't get NetBeans to recognize the various versions of org.openide.* I was trying to use.