Question

I have some OSGi-bundles (plain OSGi, no eclipse dependencies) and a maven build with pax runner that launches them in a Knopflerfish server.

The maven build and launching the bundles works perfectly fine but only via pax runner (mvn pax:provision).

For debugging the bundles it would be nice though to launch them directly from within eclipse, otherwise my breakpoints won't trigger (seems obvious, as pax:provision launches built jar-files that are not tied to eclipse anymore).

The MANIFEST.MF-file is built the usual maven-way, means using maven-bundle-plugin. Therefore launching the bundles directly from eclipse fails because the eclipse platform misses all that required external OSGi-bundles that maven gets doing it's maven magic.

Therefore I am looking for a way to set up my eclipse target platform somehow so that the OSGi-bundles from maven are automatically included and can be accessed from within the IDE for resolving the constraints at launch time.

I checked the target platform settings, but apparently one can only add specific jars and folders to it, not whole folder structures like it would require to use the whole local maven repository. If I need to update my target platform for every new dependency thats going to get really ugly (I'd wish I could do something like "add C:\Users\myprofile.m2\repository to target platform" and eclipse would just load what it needs).

While researching I found Eclipse Tycho but apparently this only compiles a target platform for building the bundles, but not for compiling and launching them from within the IDE. Next I found this site: http://andriusvelykis.github.io/pde-target-maven-plugin/ And this looks like exactly what I need. From the documentation it seems that this plugin is able to take the target platform that is compiled from eclipse tycho and write it to a file. Then I am able to import this file back into my IDE and use it as target platform.

The problem I have is, that the plugin quits with an error that I can't deduce (I turned on stacktraces for a more complete error message).

[ERROR] Failed to execute goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies (default-cli) on project orchestrator-parent: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies (default-cli) on project orchestrator-parent: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'baseDefinition' for goal lt.velykis.maven:pde-target-maven-plugin:1.0.0:add-pom-dependencies are missing or invalid
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:581)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:534)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:97)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

This is the configuration for the plugin:

        <plugin>
            <groupId>lt.velykis.maven</groupId>
            <artifactId>pde-target-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <id>pde-target</id>
                    <goals>
                        <goal>add-pom-dependencies</goal>
                    </goals>
                    <configuration>
                        <baseDefinition>D:/platform.target</baseDefinition>
                        <outputFile>D:/platform-pde.target</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I can see that the paths are correct because the platform-pde.target file is created, but it has the same content as the base file.

File content (just a standard target platform that I created and shared as the base file):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="OrchestratorPlatform" sequenceNumber="8">
<locations>
<location path="${eclipse_home}" type="Profile"/>
</locations>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
<nl>en_US</nl>
</environment>
<launcherArgs>
<vmArgs>-Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx512m</vmArgs>
</launcherArgs>
</target>

What I am looking for are tips on how to configure the plugin correctly or any other ways I can bring my maven dependency bundles into my target platform so that I can launch the bundles directly from eclipse without having to maintain the dependencies somewhere in the depths of eclipse preferences again.

Was it helpful?

Solution

You can give a try to run PAX with defining vm options for your test container. By default the container is started in a separate JVM, and you can define command line options for it. In the documentation even you will find an example to start the tests in debug mode. Just define suspend=y, and you will have enough time to attach your Eclipse with a remote debugging session.

There is also an eclipse plugin for Pax Runner, you can try that.

EDIT: With the launch config you sent me in the comment, you debugged the maven JVM, and not the OSGI container.

It is tricky to find documentation for pax:provision. I tried help:describe:

C:\>mvn help:describe -Dplugin=org.ops4j:maven-pax-plugin:1.5 -Dgoal=provision -Ddetail
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom ---
[INFO] Mojo: 'pax:provision'
pax:provision
  Description: Provision all local and imported bundles onto the selected
    OSGi framework
      mvn pax:provision [-Dframework=felix|equinox|kf|concierge] [-Dprofiles=log,war,spring,...]

    If you don't have Pax-Runner in your local Maven repository this command
    will automatically attempt to download the latest release. It will then
    continue to use this locally installed version of Pax-Runner unless you add
    -U to force it to check online for a later release, or -Drunner=version to
    temporarily use a different version.
  Implementation: org.ops4j.pax.construct.lifecycle.ProvisionMojo
  Language: java

  Available parameters:

    args
      User property: args
      URL of file containing additional Pax-Runner arguments.

    deploy (Default: true)
      User property: deploy
      When true, start the OSGi framework and deploy the provisioned bundles.

    deployPoms
      User property: deployPoms
      Comma separated list of additional POMs with bundles as dependencies.

    deployURLs
      User property: deployURLs
      Comma separated list of additional bundle URLs to deploy.

    framework
      User property: framework
      Name of the OSGi framework to deploy onto.

    noDependencies
      User property: noDeps
      Ignore bundle dependencies when deploying project.

    profiles
      User property: profiles
      Comma separated list of additional Pax-Runner profiles to deploy.

    provision
      User property: provision
      A set of provision commands for Pax-Runner.

    runner (Default: RELEASE)
      User property: runner
      The version of Pax-Runner to use for provisioning.


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.570s
[INFO] Finished at: Wed Feb 19 00:01:05 CET 2014
[INFO] Final Memory: 8M/109M
[INFO] ------------------------------------------------------------------------

So as it seems:

  1. Create a file containing the following text:

    --vmOptions=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8888

  2. Run your build like this:

    mvn pax:provision -Dargs=file:///c:/yourfilepath/thefilecontainingstuffabove.txt

I did not try it, but it can work. Suspends, port 8888, Eclipse Remote Debug :)

OTHER TIPS

I am using remote debugging with Apache Karaf a lot. There karaf also loads the bundles from the maven repository. Still eclipse finds the breakpoints and triggers them. So the same should work for pax runner.

What I do is to export KARAF_DEBUG=true and start karaf. This triggers the typical remote debugging settings which should also be available for pax runner. I then start a remote debug session from eclipse and simply add all necessary open eclipse projects to the sources of the remote debug session. This works almost all of the time. Sometimes my breaktpoints are also not triggered but it is very seldom and I did not find out why.

Btw. Karaf also allows to update bundles from the local maven repo while running. So if you change a project you can simply call mvn clean install on the single bundle project, do "update bundleid" on the shell and can continue to debug with the new version of the bundle. This is extremely helpful when you got a large project but only work at a small part while debugging.

So to resume you should be able to use pax runner with remote debugging without problems and it might also be interesting to take a look at apache karaf.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top