Q:

Using OSGi in a desktop standalone application

I am trying to write an OSGi based desktop application. I have a Swing JFrame and I want to add possibilities to add modules (other bundles). I walked through EclipseZone OSGi at JSig tutorial, but every application is started from OSGi Framework (in this case, Knopflerfish OSGi Desktop).
So my question is, whether there is an option to start the application without visible OSGi frame? I knwo, that from code, it is possible to change properties of a bundle, but how to change properties of a framework that way? (e.g. default bundle storage location, default action when bundle is in location etc.?)
public class MainFrame extends ServiceTracker implements BundleActivator {

    public MainFrame(BundleContext context, JToolBar toolBar) {
        // select, which services is the bundle tracking
        super(context, JMenu.class.getName(), null);
    }

    @Override
    public void start(BundleContext context) throws Exception {
        //display a JFrame
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        //hide a JFrame
    }

    @Override
    public Object addingService(ServiceReference reference) {
        // Process a Service and return a JMenu
        return new JMenu();
    }

    @Override
    public void removedService(ServiceReference reference, Object service) {
        // remove a JMenu from a JFrame
    }

    public static void main(String[] args) {
        // ????????????????????????????????????????????
        // ????????????????????????????????????????????
    }
}

I've written a class above (I've posted just a sketch), but I have no idea, what to write in a main() function. This bundle works fine in Knopflerfish OSGi Desktop, but I want it to run without it.

A:

Your code is basically okay, but it sounds like you want more control over the OSGi framework itself. In other words, you want to know how to launch an OSGi framework and start your bundle. The problem you have currently is that you're using somebody else's launcher (the Knopflerfish one) which includes the KF GUI Console, and you are using that to install and start your bundle. However none of that is necessary.
In AValchev's answer he talks about starting Equinox with java -jar org.eclipse.osgi.jar -console. The trouble with that approach is that it gives you an empty OSGi framework, so you will have to type commands into the OSGi shell in order to install and start your bundle... also not ideal!
I think you should write your own launcher. This is actually very simple and can be done in a way that is completely independent of any particular OSGi framework implements. I wrote about this in a blog post a little while ago.
In pseudo-code, your launcher application should look something like this:
public static void main() {

    1. get a FrameworkFactory using java.util.ServiceLoader.
    2. create an OSGi framework using the FrameworkFactory
    3. start the OSGi framework
    4. Install your bundle(s).
    5. Start all the bundles you installed.
    6. Wait for the OSGi framework to shutdown.
    
}

In your question you specifically ask about setting the bundle storage location. This can be done by setting the Constants.FRAMEWORK_STORAGE property in the Map that you pass into FrameworkFactory.newFramework method.

