You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by alen <ta...@hotmail.fr> on 2012/01/06 13:28:11 UTC

create first bundle

hello,
I'm lost in the tutorial of OSGI

I try to make a small example to create a bundle with eclipse

I find a good example in this link:
http://www.vogella.de/articles/OSGi/article.html

but honestly I'm looking for an example to create a bundle with eclipse
and deploy it to Apache karaf

So the problem is how to integrate osgi with apache karaf and with eclipse

I often find articles about eclipse equinox

and also I found several ways to test an application with OSGI either with
command or with eclipse 

thank you in advance

--
View this message in context: http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3637715.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: create first bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Alen,

do you plan to use Maven ?

Regards
JB

On 01/06/2012 01:28 PM, alen wrote:
> hello,
> I'm lost in the tutorial of OSGI
>
> I try to make a small example to create a bundle with eclipse
>
> I find a good example in this link:
> http://www.vogella.de/articles/OSGi/article.html
>
> but honestly I'm looking for an example to create a bundle with eclipse
> and deploy it to Apache karaf
>
> So the problem is how to integrate osgi with apache karaf and with eclipse
>
> I often find articles about eclipse equinox
>
> and also I found several ways to test an application with OSGI either with
> command or with eclipse
>
> thank you in advance
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3637715.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: create first bundle

Posted by alen <ta...@hotmail.fr>.
I can display a map with the notion of bundle

The code for this application is:

for the class: JGoogleMapEditorPan.java

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
 
/**
 * Afficher une carte GoogleMap dans un JEditorPane
 * @author fobec 2010
 */
public class JGoogleMapEditorPan extends JEditorPane {
 
    private int zoomFactor = 7;
    private String ApiKey = "";
    private String roadmap = "roadmap";
    public final String viewTerrain = "terrain";
    public final String viewSatellite = "satellite";
    public final String viewHybrid = "hybrid";
    public final String viewRoadmap = "roadmap";
 
    /**
     * Constructeur: initialisation du EditorKit
     */
    public JGoogleMapEditorPan() {
        HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument htmlDoc = (HTMLDocument) kit.createDefaultDocument();
        this.setEditable(false);
        this.setContentType("text/html");
        this.setEditorKit(kit);
        this.setDocument(htmlDoc);
    }
 
    /**
     * Fixer le zoom
     * @param zoom valeur de 0 à 21
     */
    public void setZoom(int zoom) {
        this.zoomFactor = zoom;
    }
 
    /**
     * Fixer la clé de developpeur
     * @param key APIKey fourni par Google
     */
    public void setApiKey(String key) {
        this.ApiKey = key;
    }
 
    /**
     * Fixer le type de vue
     * @param roadMap
     */
    public void setRoadmap(String roadMap) {
        this.roadmap = roadMap;
    }
 
    /**
     * Afficher la carte d'après des coordonnées GPS
     * @param latitude
     * @param longitude
     * @param width
     * @param height
     * @throws Exception erreur si la APIKey est non renseignée
     */
    public void showCoordinate(String latitude, String longitude, int width,
int height) throws Exception {
        this.setMap(latitude, longitude, width, height);
    }
 
    /**
     * Afficher la carte d'après une ville et son pays
     * @param city
     * @param country
     * @param width
     * @param height
     * @throws Exception erreur si la APIKey est non renseignée
     */
    public void showLocation(String city, String country, int width, int
height) throws Exception {
        this.setMap(city, country, width, height);
    }
 
    /**
     * Assembler l'url et Générer le code HTML
     * @param x
     * @param y
     * @param width
     * @param height
     * @throws Exception
     */
    private void setMap(String x, String y, Integer width, Integer height)
throws Exception {
        if (this.ApiKey.isEmpty()) {
            throw new Exception("Developper API Key not set !!!!");
        }
 
        String url = "http://maps.google.com/maps/api/staticmap?";
        url += "center=" + x + "," + y;
        url += "&amp;zoom=" + this.zoomFactor;
        url += "&amp;size=" + width.toString() + "x" + height.toString();
        url += "&amp;maptype=" + this.roadmap;
        url += "&amp;markers=color:blue" + x + "," + y;
        url += "&amp;sensor=false";
        url += "&amp;key=" + this.ApiKey;
 
        String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
Transitional//EN'>";
        html += "<html><head></head><body>";
        html += " " + url + " ";
        html += "</body></html>";
        this.setText(html);
    }
 
 
 
}


and for the class Activator.java

 
import java.util.logging.Level;
import java.util.logging.Logger;
 
import javax.swing.JFrame;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
public class Activator implements BundleActivator {
 
 
 
	public void start(BundleContext context) throws Exception {
 
 
		 JGoogleMapEditorPan googleMap = new JGoogleMapEditorPan();
 
 
 
		 try {
	            googleMap.setApiKey("maCleGoogleMap");
	            //  googleMap.setRoadmap(googleMap.viewHybrid);
 
	            /**
	            Afficher la ville de Strabourg
	             */
	            googleMap.showLocation("strasbourg", "france", 390, 400);
	            /**
	             * Afficher Paris en fonction ses coordonnées GPS
	             */
	            //  googleMap.showCoordinate("48.8667", "2.3333",390, 400);
	        } catch (Exception ex) {
	           
Logger.getLogger(JGoogleMapEditorPan.class.getName()).log(Level.SEVERE,
null, ex);
	        }
 
	        JFrame frame = new JFrame();
	        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        frame.add(googleMap);
	        frame.setSize(400, 420);
	        frame.setLocation(200, 200);
	        frame.setVisible(true);
 
 
 
 
 
 
 
 
	}
 
 
	public void stop(BundleContext context) throws Exception {
 
	}
}


and for  MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mybundle
Bundle-SymbolicName: com.test.mybundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.test.mybundle.Activator
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
import-Package: org.osgi.framework;version="1.3.0"


but the problem is if I made ​​the execution of this application:
RUN AS -> OSGI Framwork the map is displayed

but the goal is to display the map if I type "START" in the console

and close the map if I type "STOP"

for the moment if I type "START" the answer is:

osgi> start
No bundle (s) specified!


thank you in advance

--
View this message in context: http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3640145.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: create first bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
The Karaf dev guide also provides a "Creating bundle" section which can 
be helpful:

http://karaf.apache.org/manual/latest-2.2.x/developers-guide/creating-bundles.html

Regards
JB

On 01/06/2012 04:22 PM, Christian Schneider wrote:
> You could take a look at my tutorial series.
>
> http://www.liquid-reality.de/display/liquid/Karaf+Tutorials
>
> It describes how to build projects for Apache Karaf with Eclipse. There
> is no very tight integration with eclipse right now but it still works
> very well. You have quite easy deployment and also good debugging support.
>
> Christian
>
> Am 06.01.2012 13:28, schrieb alen:
>> hello,
>> I'm lost in the tutorial of OSGI
>>
>> I try to make a small example to create a bundle with eclipse
>>
>> I find a good example in this link:
>> http://www.vogella.de/articles/OSGi/article.html
>>
>> but honestly I'm looking for an example to create a bundle with eclipse
>> and deploy it to Apache karaf
>>
>> So the problem is how to integrate osgi with apache karaf and with
>> eclipse
>>
>> I often find articles about eclipse equinox
>>
>> and also I found several ways to test an application with OSGI either
>> with
>> command or with eclipse
>>
>> thank you in advance
>>
>> --
>> View this message in context:
>> http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3637715.html
>>
>> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: create first bundle

Posted by Christian Schneider <ch...@die-schneider.net>.
You could take a look at my tutorial series.

http://www.liquid-reality.de/display/liquid/Karaf+Tutorials

It describes how to build projects for Apache Karaf with Eclipse. There 
is no very tight integration with eclipse right now but it still works 
very well. You have quite easy deployment and also good debugging support.

Christian

Am 06.01.2012 13:28, schrieb alen:
> hello,
> I'm lost in the tutorial of OSGI
>
> I try to make a small example to create a bundle with eclipse
>
> I find a good example in this link:
> http://www.vogella.de/articles/OSGi/article.html
>
> but honestly I'm looking for an example to create a bundle with eclipse
> and deploy it to Apache karaf
>
> So the problem is how to integrate osgi with apache karaf and with eclipse
>
> I often find articles about eclipse equinox
>
> and also I found several ways to test an application with OSGI either with
> command or with eclipse
>
> thank you in advance
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/create-first-bundle-tp3637715p3637715.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com