Linking API and Sources to your IDE’s JARs (Part 2)

I tend to upload my complete project into version control. This includes the sources, tests, Jars and also the nbproject directory where NetBeans stores the project configuration. By doing so, I can check out the project on a different machine and start quickly without having to configure the project.

Sources and API Docs of external libraries are not commited as they’re are not requried for compiling. I usually keep sources and docs in a separate place outside my project (let’s say <userdir>javaLibs...).

When I check out the project on a different machine I can do coding but I do have neither the sources nor the API docs. Even worse: as I’ve commited the whole project including the configuration, I have also commited the nbproject/project.properties file which stores the pathes to the source and docs. Which is not a problem if the pathes on all the machines are the same. But when a new contributer wants to join in, (s)he either has to use the same directory structure (and possibly the same OS) or he has to overwrite the settings. Both not very desirable.

But this issue can be solved in some ways – some more or less convenient:

  1. Don’t care about it. Download the sources and docs for each JAR and edit the source and API doc links manually and relink them. That’s inconvenient.
  2. Bundle sources and Docs in a single Zip which is provided as a separate download (or repository). Then just set up a rule that this zip MUST be unpacked into a certain directrory. Inconvenient as well as you try to dictate the directory structure.
  3. Use the NetBeans Library feature (Tools > Libraries) to bundle libs, docs and sources. Unfortunately I have not yet discovered a way to share these Libraries. So that’s inconvenient as well!

The optimal solution (for me): Use a NetBeans variable for the path

  1. Put the Jars, sources and docs in a separate directory like <userdir>javaLibs
  2. Create a downloadable archive with all the files (sources and docs) and make it accessible.
  3. Create a NetBeans Variable: Tools > Variables > Add
  4. Name: “libDir
  5. Location: “the location where you put all your libs”, <userdir>javaLibs in my case
  6. When importing a new JAR into your project, put the jar into your project’s libDir
  7. Copy API and sources into subdirectory under libDir
  8. link API and sources in NetBeans by using the option:
    Project Properties > Libraries > select the Jar > Edit > Browse > hit the “…”  button besides “Path from Variable” and select the file or folder

A new conributor just needs to

  • check out the project
  • create a libDir NetBeans variable pointing to a certain directory
  • check out/download the API/Src and unpack it into libDir

Leave a Reply

Your email address will not be published. Required fields are marked *