title: Why won't my OSGI example print "Hello World" on bundle start?
body: <p>Taking an example from Neil Bartlett's book "OSGi in Practice", I copied the following code which can start, stop, and check for bundles in a directory, and which is supposed to print messages on bundle start and stop:</p>
  
  <pre><code>package tutorial;
  import java.io.File;
  import org.osgi.framework.Bundle;
  import org.osgi.framework.BundleActivator;
  import org.osgi.framework.BundleContext;
  import org.osgi.framework.BundleException;
  
  public class HelloUpdaterActivator implements BundleActivator {
  // ...
  private final Thread thread = new Thread(new BundleUpdater());
  private volatile BundleContext context;
  
  @Override
  public void start(BundleContext context) throws Exception {
      System.out.println("Hello World");
      this.context = context;
      thread.start();
  }
  
  @Override
  public void stop(BundleContext context) throws Exception {
      System.out.println("Goodbye World");
      thread.interrupt();
  }
  
  protected Bundle findBundleByLocation(String location) {
      // ... Not relevant to lack of any print statements in OSGi console.
  }
  
  private class BundleUpdater implements Runnable {
      @Override
      public void run() {
          // ... Not relevant to lack of any print statements in OSGi console.
      }
  }
  </code></pre>
  
  <p>^ I put it in a file called HelloUpdaterActivator.java and put that java file in a folder called "tutorial" along with org.eclipse.osgi_3.5.1.R35x_v20090827.jar (The jar file for OSGi that came with an old version of the Eclipse Equinox implementation of OSGi). </p>
  
  <p>I successfully compiled the tutorial java file with: </p>
  
  <pre><code>javac -cp ".:org.eclipse.osgi_3.5.1.R35x_v20090827.jar" HelloUpdaterActivator.java
  </code></pre>
  
  <p>Then I took all the class files that were generated and put them into a jar like so:</p>
  
  <pre><code>jar cf HelloUpdaterActivator.jar ./HelloUpdaterActivator.class ./HelloUpdaterActivator\$BundleUpdater.class ./HelloUpdaterActivator\$1.class
  </code></pre>
  
  <p>Finally, I made a generic sample MANIFEST.MF file for the jar, like so:</p>
  
  <pre><code>Manifest-Version: 1.0
  Created-By: 1.7.0_79 (Oracle Corporation)
  Bundle−Name: OSGi Bundle
  Bundle−Symbolic Name: example1
  Bundle−Version: 1.0.1
  Bundle−Required Execution Environment: J2SE−1.6
  </code></pre>
  
  <p>Now that the jar was ready, I opened up OSGi in the terminal with its own little console, like so:</p>
  
  <pre><code>java -jar ./org.esgi_3.5.1.R35x_v20090827.jar -console -configuration runtime
  </code></pre>
  
  <p>The OSGi console looked like this:</p>
  
  <pre><code>osgi&gt; 
  </code></pre>
  
  <p>Into the OSGi console I typed:</p>
  
  <pre><code>osgi&gt; install file:HelloUpdaterActivator.jar
  Bundle id is 1
  osgi&gt; ss
  
  Framework is launched.
  
  id  State       Bundle
  0   ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827
  1   INSTALLED   unknown_0.0.0 [1]
  
  osgi&gt; start 1
  osgi&gt; ss
  
  Framework is launched.
  
  id  State       Bundle
  0   ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827
  1   ACTIVE      unknown_0.0.0 [1]
  
  osgi&gt; stop 1
  
  osgi&gt; ss
  
  Framework is launched.
  
  id  State       Bundle
  0   ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827
  1   RESOLVED    unknown_0.0.0 [1]
  </code></pre>
  
  <p>But even though it says that the jar file I made is active, "Hello World" never prints on start and "Goodbye World" never prints on stop. Why won't my OSGi tutorial print "Hello World" on bundle start or "Goodbye world" on bundle stop?</p>
  
  <p>UPDATE</p>
  
  <p>I got it working by changing my MANIFEST.MF file to:</p>
  
  <pre><code>Manifest-Version: 1.0  
  Bundle-ManifestVersion: 2
  Bundle-Name: OSGi_Bundle - Activator  
  Bundle-Version: 1.0.0.SNAPSHOT
  Bundle-Activator: Activator  
  Bundle-ClassPath: .
  Bundle-Description: Activator
  Bundle-SymbolicName: activator
  Import-Package: org.osgi.framework
  </code></pre>