- It requires only two jar files for basic features support
- Just few lines of code for management operations are needed.
- Community on the mailing lists is very responsive
- https://www.opends.org/wiki/page/UsingOpenDSAsAnEmbeddedApplication
- https://www.opends.org/wiki/attach/OpenDSPresentations/OpenDS_Jazoon08.pdf
- http://wiki.interldap.objectweb.org/xwiki/bin/view/Main/EmbeddedLDAP
- Download OpenDS 1.0.0 and unzip it.
- Fire the 'setup' config script from the main directory and alter the configuration as you need. Remember to shutdown the server if you let to start it.
- Embedded OpenDS will require a special directory structure to be able to start. All needed files can be copied from the server directory and are shown on the picture below:
The 'db' directory can be left empty if you want to add the root entry manually in the code - Copy OpenDS.jar and je.jar files from OpenDS-1.0.0/lib/ directory and add them to the project classpath
- Edit opends/config/config.ldif and remove following entry:
dn: cn=SNMP Connection Handler,cn=Connection Handlers,cn=config
objectClass: top
objectClass: ds-cfg-snmp-connection-handler
objectClass: ds-cfg-connection-handler
ds-cfg-listen-port: 161
ds-cfg-enabled: false
ds-cfg-trap-port: 162
ds-cfg-java-class: org.opends.server.snmp.SNMPConnectionHandler
cn: SNMP Connection Handler
(This entry requires to have OpenDS-1.0.0/lib/extensions/snmp-mib2605.jar file on the classpath)
public class OpenDSService
{
private String serverRoot = "";
public DirectoryEnvironmentConfig getConfig()
{
DirectoryEnvironmentConfig config = new DirectoryEnvironmentConfig();
try
{
// Server root points to the directory with opends configuration
config.setServerRoot(new File(getServerRoot()));
config.setForceDaemonThreads(true);
}
catch (InitializationException e)
{
e.printStackTrace();
}
return config;
}
public void start()
{
if (!EmbeddedUtils.isRunning())
{
try
{
EmbeddedUtils.startServer(getConfig());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public void stop()
{
if (EmbeddedUtils.isRunning())
{
EmbeddedUtils.stopServer(this.getClass().getName(), null);
}
}
public String getServerRoot()
{
return serverRoot;
}
public void setServerRoot(String serverRoot)
{
this.serverRoot = serverRoot;
}
}
Here there is a trivial example maven project that starts opends and performs simple JNDI search.
2 comments:
Hello,
Thanks much for the howto. Much better than the official wiki I've found.
I just did a regular OpenDS 2.3.0-build002 install through webstart. Configured a server, added data through the manager application which can be started from the installer.
Then copied the files you have listed in your howto to another location to be used as the embedded server root directory.
For SSL to work (as configured with the GUI installer) I needed also to copy config/*store* files to the embedded server root directory.
So that's all. Put OpenDS.jar and je.jar to classpath and I now have an embedded OpenDS server running like you show in your sample code.
Thank you!
P.S. the only bad thing is that opends is not available through a public maven repo, at least nothing but 1.0 version.
Post a Comment