Why can't I add a library to the classpath of my freeform project?

While Netbeans could provide the capability to add a library to the classpath, there is no practical way to modify an existing Ant build script to incorporate the change, therefore Netbeans' developers currently only support the manual additional of a classpath for completion and documentation on a project by project basis.

The following discussion rather snarkily addresses the issue in more detail and may provide some idea of what some of the developers feel about this request, but at its core answers the FAQ by saying, "we think you're too dumb to realize why the convenience is not a big enough priority to us due to the limitations of the solution". Nevertheless, the response is educational, even if it doesn't cover the needs of large multi-module team projects, which are the least likely to be able to settle on Netbeans' native project types, and more often must use freeform projects.

(Original response, kept for discussion value, despite the multitude of assumptions made)

This subject is not as simple as it sounds when you first look at it. While standard Java projects (j2seprojects) and freeform projects superficially share some UI elements, what's going on underneath is quite different, and some analogies just don't work.

There are two possible meaning for this request.

  1. "Add Library" with the same semantics as for a j2seproject - i.e. actually change the classpath Ant will use. This is nontrivial in simple cases, very tricky in common cases, and impossible in the general case (Halting Problem). The IDE simply cannot know for sure how the Ant script is ultimately going to get its classpath, so it cannot reliably change that classpath.
  2. "Add Library" with nearly the same semantics as "Add JAR/Folder" in the freeform customizer already has. I.e., it lets you pick a library, then looks at the current list of JARs in it, and adds those to <classpath> in project.xml for code completion. Maybe also listens for future changes in the library's JAR list and quietly updates project.xml to match. In either case, the Ant script's behavior is unaffected. This is certainly possible to implement, it's just that the user might be quite surprised by the fact that the GUI apparently exists but does not behave at all the same as in standard projects.

When most people ask something similar to what you asked here, really they are asking for one of several things, which they usually don't make explicit:

  1. I want Add Library to exist and to change my Ant script (or some properties file it loads) to match. Actually, I want Add JAR to do the same. I want the IDE to study my Ant script, infer what XML or properties or whatever it is using to create a classpath, then magically make the most natural possible modification to my build infrastructure that would result in the classpath I am now configuring in the GUI.
  2. Sort of like #1, but I don't care about using an existing mature Ant script, and I don't want to spend much time writing Ant targets. What I really wanted was some sort of project type that was a mixture of standard Java projects and freeform projects, which would give me a Libraries panel where I could make classpath changes just like in standard Java projects, which would get written to some properties file that Ant could load; and the IDE would set up some initial compilation targets for me that would load that properties file, so if I don't make big changes to it, I could control the classpath from the GUI. I'd like to have the option to set up additional Ant targets with context menu item bindings, and configure some complicated stuff involving multiple asymmetric source roots and computed classpaths, but later - right now I'm not doing anything that special.
  3. Add JAR as it is is OK, but it happens that I already have this JAR listed in some library and I don't want to bother browsing to it again in the filechooser, especially as Swing's filechooser is so hard to use. My Ant script is already using the library JAR but it is too awkward to copy and paste the path from there. And I do not want to, or do not know how to, edit project.xml as text to make the IDE's notion of the classpath automatically match Ant's, by sharing some property definition files.
  4. I don't really care about "JAR" vs. "library" at all, I just want to associate some sources and/or Javadoc with this JAR, and there is no button in the freeform Libraries panel to do that yet. I could make a library with matching JARs and configure sources and/or Javadoc there, which will work, but I don't know that, or I know that but it's so awkward.

Some or all of these requests could be satisfied in the future, I guess. #3 and #4 should not be too hard (though there are some details that make #4 tricky). #2 should be possible though it's a significant undertaking to make it a production quality, polished feature. #1 is a good candidate for a PhD thesis.

Applies to: NetBeans 4.0 and later

Platforms: All

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo