If you have a Java application and want to start an embedded Nuxeo and use its APIs from the same JVM, you can do the following (Nuxeo 5.4).
With the Nuxeo JARs in your classpath
If the Nuxeo JARs are already in your classpath, then you can simply use FrameworkLoader:
The following variables have to be initialized:
- wd is the home directory of Nuxeo (the directory where you have the config folder and other Nuxeo folders),
- bundles is a list of files with all the Nuxeo bundles that you want to start,
- env is a property map to initialize the Nuxeo Environment (locations of the different Nuxeo folders). The env map can be an empty map; you need to put properties inside only if you want to change the default Nuxeo directory locations.
With the Nuxeo JARs not in your classpath
If you don't have the Nuxeo JARs already in your application classpath, you cannot directly invoke the FrameworkLoader object (since it's not in your classpath). In that case you need to use a facade that will load Nuxeo in a mutable classloader and invoke FrameworkLoader through reflection.
You can find an example of such of a facade in the class org.nuxeo.osgi.application.FrameworkBootstrap (in nuxeo-runtime-launcher).
You can reuse it to start Nuxeo as we are doing in nuxeo-runtime-tomcat-adapter:
The MutableClassLoader is used to be able to insert Nuxeo bundles into the classloader. You can use the default implementation: MutableClassLoaderDelegate or implement your own MutableClassLoader.
See the FrameworkBootstrap class in nuxeo-runtime-tomcat-adapter for more details on how it works.