You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by Lindsay Smith <li...@coretech.co.nz> on 2011/09/12 04:38:17 UTC

Starting embedded Karaf from Java - reliance on System properties

I'm investigating launching Karaf from within Java and I have some questions about setting Karaf's configuration properties.

I think Karaf shows a whole lot of promise as the foundation for OSGi products, I'd love to be able to use it and I'm looking forward to the 3.0 release as it appears to have a bunch of stuff I think makes it very useful.  The embedded scenario is very important to me as well, hence the questions.   We currently use Equinox directly with their servlet bridge.

When using the startup script, a bunch of system properties are set when launching the Java process.     When launching Karaf from Java, the only example I've seen is the web container example that I think is in the source.  It sets a bunch of system properties via Java before calling the launcher class.

Is Karaf dependent on system properties to configure itself?  Is there any other way to give Karaf the config information it needs?

I see that there is a system.properties file in the /etc folder - does Karaf simply use this file - after modifying the values from matching system properties that are present?

While system properties are fine when you have are launching the Java process yourself, it's not appropriate to set them or read them in an embedded situation, as you don't always have control over how that process was launched, or what other classes are reading or setting system properties within the same process.    In an embedded situation if you set system properties in code then you've limited yourself to a single Karaf instance being launched from that process.

As an ideal solution, lauching Karaf from Java would pass in a map of configuration values.  We could then write wrappers that, for example, pull configuration values from the servlet context, or from an external properties file that contains the initial values.

Thanks for any feedback

Lindsay





RE: Starting embedded Karaf from Java - reliance on System properties

Posted by Lindsay Smith <li...@coretech.co.nz>.
Hi Andreas,

Thanks for taking the time to reply.  

The reason that embedding is interesting to me is the nature of the product that we develop.  It is OSGi based internally, but is an enterprise web application product.  One of the options we give to clients for installing the product is to install it inside an existing web container - WebSphere etc.   It's then managed like any other web application from their point of view.

We converted it to OSGI just over a year ago, and we've got our own system of specifying the building the set of bundles that make up the product.  The Karaf design is very attractive for all this stuff, hence my interest.     Switching over to using Karaf would mean either finding a way to embed it, or ditching that deployment option (which I'd prefer but, customers, money, etc).  

Thanks for explaining that the System properties go deeper than just startup - this must make things a lot simpler from a code point of view as you don't have to keep passing the config around everywhere.   I've always thought it would be better if Java allowed you scope System properties (like by ClassLoader or something) but I'm dreaming if I expect that to change any time soon.

Thanks for the feedback, and keep up the good work, I'm looking forward to 3.0.0.

Lindsa


-----Original Message-----
From: Andreas Pieber [mailto:anpieber@gmail.com] 
Sent: Thursday, 15 September 2011 6:41 a.m.
To: dev@karaf.apache.org
Subject: Re: Starting embedded Karaf from Java - reliance on System properties

Hey Lindsay,

Well, the problem here is that Karaf is not really made to run embedded.
This is similar to a situation where you would like to start JBoss or Glassfish embedded. Even if you use jetty/tomcat embedded you do so to add one functionality: servlets. Something similar is true for Karaf. I'm curious if it isn't the better solution to use plain felix/equinox if you like to start an embedded OSGi engine. Nevertheless, may I ask what you like to do with an embedded Karaf?

OK, back to you question: currently there is no option to configure Karaf by a map of properties. In addition the question is: how useful this will be.
The internal parts of Karaf make quite heavy use of
System.getProperty(KARAF_HOME) and similar properties. This is also the reason why Karaf does the following shortly after startup:

System.setProperty(PROP_KARAF_HOME, karafHome.getPath()); System.setProperty(PROP_KARAF_BASE, karafBase.getPath()); System.setProperty(PROP_KARAF_DATA, karafData.getPath()); System.setProperty(PROP_KARAF_INSTANCES, karafInstances.getPath());

Therefore, even if you can put those properties in via a MAP they will (and have to be) still be set as system props. So no real solution here.

@The system.properties: Karaf doesn't uses this file but rather provides the values in there as system properties again. You can see all this behavior here [1]

I'm afraid there is no way to remove all of them. Some things wouldn't even work if the sys properties aren't set.

Kind regards,
Andreas

[1]
https://svn.apache.org/repos/asf/karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java

On Mon, Sep 12, 2011 at 04:38, Lindsay Smith <li...@coretech.co.nz> wrote:

> I'm investigating launching Karaf from within Java and I have some 
> questions about setting Karaf's configuration properties.
>
> I think Karaf shows a whole lot of promise as the foundation for OSGi 
> products, I'd love to be able to use it and I'm looking forward to the 
> 3.0 release as it appears to have a bunch of stuff I think makes it very useful.
>  The embedded scenario is very important to me as well, hence the questions.
>   We currently use Equinox directly with their servlet bridge.
>
> When using the startup script, a bunch of system properties are set when
> launching the Java process.     When launching Karaf from Java, the only
> example I've seen is the web container example that I think is in the 
> source.  It sets a bunch of system properties via Java before calling 
> the launcher class.
>
> Is Karaf dependent on system properties to configure itself?  Is there 
> any other way to give Karaf the config information it needs?
>
> I see that there is a system.properties file in the /etc folder - does 
> Karaf simply use this file - after modifying the values from matching 
> system properties that are present?
>
> While system properties are fine when you have are launching the Java 
> process yourself, it's not appropriate to set them or read them in an 
> embedded situation, as you don't always have control over how that 
> process was launched, or what other classes are reading or setting system properties
> within the same process.    In an embedded situation if you set system
> properties in code then you've limited yourself to a single Karaf 
> instance being launched from that process.
>
> As an ideal solution, lauching Karaf from Java would pass in a map of 
> configuration values.  We could then write wrappers that, for example, 
> pull configuration values from the servlet context, or from an 
> external properties file that contains the initial values.
>
> Thanks for any feedback
>
> Lindsay
>
>
>
>
>

Re: Starting embedded Karaf from Java - reliance on System properties

Posted by Andreas Pieber <an...@gmail.com>.
Hey Lindsay,

Well, the problem here is that Karaf is not really made to run embedded.
This is similar to a situation where you would like to start JBoss or
Glassfish embedded. Even if you use jetty/tomcat embedded you do so to add
one functionality: servlets. Something similar is true for Karaf. I'm
curious if it isn't the better solution to use plain felix/equinox if you
like to start an embedded OSGi engine. Nevertheless, may I ask what you like
to do with an embedded Karaf?

OK, back to you question: currently there is no option to configure Karaf by
a map of properties. In addition the question is: how useful this will be.
The internal parts of Karaf make quite heavy use of
System.getProperty(KARAF_HOME) and similar properties. This is also the
reason why Karaf does the following shortly after startup:

System.setProperty(PROP_KARAF_HOME, karafHome.getPath());
System.setProperty(PROP_KARAF_BASE, karafBase.getPath());
System.setProperty(PROP_KARAF_DATA, karafData.getPath());
System.setProperty(PROP_KARAF_INSTANCES, karafInstances.getPath());

Therefore, even if you can put those properties in via a MAP they will (and
have to be) still be set as system props. So no real solution here.

@The system.properties: Karaf doesn't uses this file but rather provides the
values in there as system properties again. You can see all this behavior
here [1]

I'm afraid there is no way to remove all of them. Some things wouldn't even
work if the sys properties aren't set.

Kind regards,
Andreas

[1]
https://svn.apache.org/repos/asf/karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java

On Mon, Sep 12, 2011 at 04:38, Lindsay Smith <li...@coretech.co.nz> wrote:

> I'm investigating launching Karaf from within Java and I have some
> questions about setting Karaf's configuration properties.
>
> I think Karaf shows a whole lot of promise as the foundation for OSGi
> products, I'd love to be able to use it and I'm looking forward to the 3.0
> release as it appears to have a bunch of stuff I think makes it very useful.
>  The embedded scenario is very important to me as well, hence the questions.
>   We currently use Equinox directly with their servlet bridge.
>
> When using the startup script, a bunch of system properties are set when
> launching the Java process.     When launching Karaf from Java, the only
> example I've seen is the web container example that I think is in the
> source.  It sets a bunch of system properties via Java before calling the
> launcher class.
>
> Is Karaf dependent on system properties to configure itself?  Is there any
> other way to give Karaf the config information it needs?
>
> I see that there is a system.properties file in the /etc folder - does
> Karaf simply use this file - after modifying the values from matching system
> properties that are present?
>
> While system properties are fine when you have are launching the Java
> process yourself, it's not appropriate to set them or read them in an
> embedded situation, as you don't always have control over how that process
> was launched, or what other classes are reading or setting system properties
> within the same process.    In an embedded situation if you set system
> properties in code then you've limited yourself to a single Karaf instance
> being launched from that process.
>
> As an ideal solution, lauching Karaf from Java would pass in a map of
> configuration values.  We could then write wrappers that, for example, pull
> configuration values from the servlet context, or from an external
> properties file that contains the initial values.
>
> Thanks for any feedback
>
> Lindsay
>
>
>
>
>