Difference between revisions of "OSGi : Install Eclipse Plugins"
JAnastasiade (talk | contribs) m |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:OSGi]] | + | [[Category:OSGi]]{{Ecl_menu}} |
− | [[Category:ECL_Activities]] | + | [[Category:ECL_Activities]]__NOTOC__ |
+ | {{Ecl_installation|type=OSGi|type-small=osgi|name=Eclipse Classic|install=Follow this [http://www.vogella.de/articles/OSGi/article.html tutorial to build OSGi bundels after you install Elcipse Classic]}} | ||
− | [http:// | + | <h3>Steps for Building the first Bundle</h3> |
+ | |||
+ | <h4>1. Study the Interfaces</h4> | ||
+ | |||
+ | * [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/Bundle.html Bundle] | ||
+ | * [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html BundleContext] | ||
+ | * [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator] | ||
+ | ---------- | ||
+ | |||
+ | <h4>2. Define the BundleActivator class</h4> | ||
+ | |||
+ | The ''BundleActivator'' customizes the starting and stopping of a bundle. | ||
+ | |||
+ | ''BundleActivator'' is an interface that may be implemented when a bundle is started or stopped. The Framework can create instances of a bundle's ''BundleActivator'' as required. If an instance's ''BundleActivator.start'' method executes successfully, it is guaranteed that the same instance's ''BundleActivator.stop'' method will be called when the bundle is to be stopped. The Framework must not concurrently call a BundleActivator object. | ||
+ | |||
+ | ''BundleActivator'' is specified through the Bundle-Activator Manifest header. | ||
+ | <source lang="java"> | ||
+ | package cs.ecl.osgi.simple.helloworld; | ||
+ | |||
+ | import org.osgi.framework.BundleActivator; | ||
+ | import org.osgi.framework.BundleContext; | ||
+ | |||
+ | public class Activator implements BundleActivator { | ||
+ | |||
+ | private static BundleContext context; | ||
+ | |||
+ | static BundleContext getContext() { | ||
+ | return context; | ||
+ | } | ||
+ | |||
+ | public void start(BundleContext bundleContext) throws Exception { | ||
+ | Activator.context = bundleContext; | ||
+ | System.out.println("Hello World from OSGi - start method in BundleActivator!"); | ||
+ | } | ||
+ | |||
+ | public void stop(BundleContext bundleContext) throws Exception { | ||
+ | Activator.context = null; | ||
+ | System.out.println("Goodby World from OSGi - stop method in BundleActivator!"); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <h4>2. Define the MANIFEST.MF</h4> for the ''cs.ecl.osgi.simple.helloworld'' bundle | ||
+ | |||
+ | <source lang="xml"> | ||
+ | Manifest-Version: 1.0 | ||
+ | Bundle-ManifestVersion: 2 | ||
+ | Bundle-Name: Helloworld | ||
+ | Bundle-SymbolicName: cs.ecl.osgi.simple.helloworld | ||
+ | Bundle-Version: 1.0.0.qualifier | ||
+ | Bundle-Activator: cs.ecl.osgi.simple.helloworld.Activator | ||
+ | Bundle-Vendor: Seneca College - Eclipse Course | ||
+ | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 | ||
+ | Import-Package: org.osgi.framework;version="1.3.0" | ||
+ | Bundle-ActivationPolicy: lazy | ||
+ | </source> | ||
+ | |||
+ | The file defines: | ||
+ | 1. The bundle identity by headers value of Bundle-SymbolicName and Bundle-Version | ||
+ | |||
+ | cs.ecl.osgi.simple.helloworld & 1.0.0.qualifier | ||
+ | |||
+ | 2. The bundle requirements by header value of Import-Package | ||
+ | |||
+ | org.osgi.framework;version="1.3.0" | ||
+ | |||
+ | 3. The bundle activator by header value Bundle-Activator | ||
+ | |||
+ | cs.ecl.osgi.simple.helloworld.Activator |
Latest revision as of 14:17, 23 January 2011
Main Page · Course Description · Course Topics · Schedule, Students, Teams · Course Resources · Course Projects
Install Eclipse OSGi
- Go to Eclipse Downloads and choose Eclipse Classic (attention at operating system 32/64 bit).
- Unzip the downloaded file in /Eclipse_Platform/OSGi directory.
- Start Eclipse (click the eclipse executable file in /Eclipse_Platform/OSGi/eclipse directory
- In the dialog box:Workspace Launcher -> Workspace type: ./wskp/{app-type} where {app-type} could be: hello or simple or lab
Follow this tutorial to build OSGi bundels after you install Elcipse Classic
For this course you will be using the workspace defined in /Eclipse_Platform/OSGi/eclipse/wksp/...
The root directory for this course is: Eclipse_Platform
|
where:
|
Check your working environment by running the Hello Sample from Course Repository
You may also want to install JUnit Library to be able to debug your applications.
To install JUnit follow the instructions:
- Download JUnit4.x.jar from the JUnit website . The download contains a "junit-4.*.jar" which is the JUnit library.
- To make JUnit available in your Java project you have to add the the JUnit library file to your Java classpath. (If you do not know how to do it, please use this Eclipse tutorial to learn how to add jar files to your Eclipse project).
Steps for Building the first Bundle
1. Study the Interfaces
2. Define the BundleActivator class
The BundleActivator customizes the starting and stopping of a bundle.
BundleActivator is an interface that may be implemented when a bundle is started or stopped. The Framework can create instances of a bundle's BundleActivator as required. If an instance's BundleActivator.start method executes successfully, it is guaranteed that the same instance's BundleActivator.stop method will be called when the bundle is to be stopped. The Framework must not concurrently call a BundleActivator object.
BundleActivator is specified through the Bundle-Activator Manifest header.
package cs.ecl.osgi.simple.helloworld;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
System.out.println("Hello World from OSGi - start method in BundleActivator!");
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
System.out.println("Goodby World from OSGi - stop method in BundleActivator!");
}
}
2. Define the MANIFEST.MF
for the cs.ecl.osgi.simple.helloworld bundleManifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Helloworld
Bundle-SymbolicName: cs.ecl.osgi.simple.helloworld
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: cs.ecl.osgi.simple.helloworld.Activator
Bundle-Vendor: Seneca College - Eclipse Course
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-ActivationPolicy: lazy
The file defines: 1. The bundle identity by headers value of Bundle-SymbolicName and Bundle-Version
cs.ecl.osgi.simple.helloworld & 1.0.0.qualifier
2. The bundle requirements by header value of Import-Package
org.osgi.framework;version="1.3.0"
3. The bundle activator by header value Bundle-Activator
cs.ecl.osgi.simple.helloworld.Activator