Tuesday, February 12, 2008

Using LDAP SDK on OS X with NetBeans

As an example of integrating an external jar for use with NB in java projects ... Probably it is better to stick with what is provided by JNDI, it is much better now, but if you have a project that uses ldapsdk.jar: 

  • Download  ldapsdk_java_20020819.zip from http://www.mozilla.org/directory/javasdk.html
  • Unzip it, there is a buildjsdk.txt that hints about the next steps
  • cd to mozilla/directory/java-sdk
  • execute make -f ldap.mk JAVA_VERSION=1.4 to get .class files (optional)
  • execute make -f ldap.mk basepackage to make the ldapsdk.jar (optional, previous command required: 301968 vs 301913 bytes in the jar I "inherited")
  • execute make -f ldap.mk doc JAVA_VERSION=1.4 (to generate javadoc)
To successfully execute the previous commands you may need to:
edit ldap.mk : add -source 1.4 -target 1.4 to each JAVAC variable definition like:
JAVAC=$(JDKBIN)javac -g -classpath "$(JAVACLASSPATH)" -source 1.4 -target 1.4
---
JAVAC=$(JDKBIN)javac -g -classpath "$(JAVACLASSPATH)"

create some environment vars: export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home
All this mess  is needed because the sdk uses enum as an identifier, and Java 5 uses enum for the typesafe enumeration pattern, as a reserved word. You need to either change the source code or compile for Java 1.4 ... So much for Java's backward compatibility. Still, you may get some deprecation warnings ...
  • Open NB (5.5.1): Tools -> Library Manager
  • Create a new library
  • add ldapjdk.jar to Classpath
  • add ./mozilla/directory/java-sdk to Sources
  • add ./doc to Javadoc
Add to your project the library you just created (and maybe remove the previous jar). You may need to restart Netbeans (to reload the classpath).
Test: 
  • Try MR-> Go to Source
  • Put breakpoints 
  • Use the "." for contextual javadoc, code completion ...


I hope my next NB entry will be about a detailed installation of Scala support in NetBeans (see Caoyuan's fine work)


No comments: