You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Jared Stofflett <st...@gmail.com> on 2018/10/29 15:58:59 UTC

Is it possible to launch Karaf and debug user code from Eclipse?

I currently use an Equinox container with an embedded Jetty server to
run webapps that make use of OSGI bundles. I'd like to use Karaf
instead of plain Equinox. Currently I can build my code in eclipse
with out a full maven build, and have those changes show up if I'm
running the OSGI container in debug mode. Is it possible to create a
launch configuration to do this with Karaf? All the tutorials I've
looked at so far require you to build your bundle, start Karaf with
debug mode enabled, and use a remote debug session. This would be a
step backword from my current setup.

Re: Is it possible to launch Karaf and debug user code from Eclipse?

Posted by Francois Papon <fr...@openobject.fr>.
Hi Steinar,

Very good explanation ;)

regards,

François Papon
fpapon@apache.org

Le 30/10/2018 à 10:36, Steinar Bang a écrit :
>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
>> Hi Jared,
>> you can start karaf in debug mode:
>> bin/karaf debug
>> Then you can plug Eclipse debugger using port 5005 (default).
>> You can directly deploy your bundle from eclipse in Karaf.
>> So basically, you have a Karaf instance running, executing your eclipse
>> bundle. You can rebuild your bundle in eclipse and then just do a
>> bundle:update in Karaf. You will have basically the same as you have today.
> Here's what I do:
>  1. Start karaf in debug mode like JB showed above
>  2. Connect eclipse remote debugging to port 5005
>  3. Build the application that is to be debugged with "mvn clean install"
>     to ensure that a SNAPSHOT version of my application is in the local
>     maven repository, eg. like so:
>      git clone https://github.com/steinarb/frontend-karaf-demo.git
>      cd frontend-karaf-demo.git
>      mvn clean install
>  3. From the karaf console:
>    a. Add the feature repository
>        feature:repo-add mvn:no.priv.bang.demos/frontend-karaf-demo/LATEST/xml/features
>    b. Install the feature from the repository that will pull in the
>       application as well as all required run time dependencies:
>        feature:install frontend-karaf-demo
>    c. Make karaf watch for new SNAPSHOT versions in the local maven
>       repository:
>        bundle:watch *
>
> After this, every time you build your bundle(s) with maven, karaf will
> reload them from the new SNAPSHOT versions in the local repository.
>
> You can either do the maven build from an eclipse run configuration, or
> from a command line.  When debugging I try to make the builds as brief
> as possible, so I usually do something like this, in the pom.xml
> directory of just the bundle I'm debugging:
>  mvn install -DskipTests=true -Dmaven.javadoc.skip=true -DskipSource=true
>
> I add a "clean" to that command if I've moved or renamed or deleted
> something.  You can skip source attachments, since eclipse will pick up
> the source from the bundle project.
>
> See this blog post for some further reading:
>  https://steinar.bang.priv.no/2018/02/10/develop-osgi-applications-using-karaf/
>


Re: Is it possible to launch Karaf and debug user code from Eclipse?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:

> Hi Jared,
> you can start karaf in debug mode:

> bin/karaf debug

> Then you can plug Eclipse debugger using port 5005 (default).

> You can directly deploy your bundle from eclipse in Karaf.

> So basically, you have a Karaf instance running, executing your eclipse
> bundle. You can rebuild your bundle in eclipse and then just do a
> bundle:update in Karaf. You will have basically the same as you have today.

Here's what I do:
 1. Start karaf in debug mode like JB showed above
 2. Connect eclipse remote debugging to port 5005
 3. Build the application that is to be debugged with "mvn clean install"
    to ensure that a SNAPSHOT version of my application is in the local
    maven repository, eg. like so:
     git clone https://github.com/steinarb/frontend-karaf-demo.git
     cd frontend-karaf-demo.git
     mvn clean install
 3. From the karaf console:
   a. Add the feature repository
       feature:repo-add mvn:no.priv.bang.demos/frontend-karaf-demo/LATEST/xml/features
   b. Install the feature from the repository that will pull in the
      application as well as all required run time dependencies:
       feature:install frontend-karaf-demo
   c. Make karaf watch for new SNAPSHOT versions in the local maven
      repository:
       bundle:watch *

After this, every time you build your bundle(s) with maven, karaf will
reload them from the new SNAPSHOT versions in the local repository.

You can either do the maven build from an eclipse run configuration, or
from a command line.  When debugging I try to make the builds as brief
as possible, so I usually do something like this, in the pom.xml
directory of just the bundle I'm debugging:
 mvn install -DskipTests=true -Dmaven.javadoc.skip=true -DskipSource=true

I add a "clean" to that command if I've moved or renamed or deleted
something.  You can skip source attachments, since eclipse will pick up
the source from the bundle project.

See this blog post for some further reading:
 https://steinar.bang.priv.no/2018/02/10/develop-osgi-applications-using-karaf/


Re: Is it possible to launch Karaf and debug user code from Eclipse?

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

you can start karaf in debug mode:

bin/karaf debug

Then you can plug Eclipse debugger using port 5005 (default).

You can directly deploy your bundle from eclipse in Karaf.

So basically, you have a Karaf instance running, executing your eclipse
bundle. You can rebuild your bundle in eclipse and then just do a
bundle:update in Karaf. You will have basically the same as you have today.

Regards
JB

On 29/10/2018 16:58, Jared Stofflett wrote:
> I currently use an Equinox container with an embedded Jetty server to
> run webapps that make use of OSGI bundles. I'd like to use Karaf
> instead of plain Equinox. Currently I can build my code in eclipse
> with out a full maven build, and have those changes show up if I'm
> running the OSGI container in debug mode. Is it possible to create a
> launch configuration to do this with Karaf? All the tutorials I've
> looked at so far require you to build your bundle, start Karaf with
> debug mode enabled, and use a remote debug session. This would be a
> step backword from my current setup.
>