将OSGi包的maven依赖项添加到Eclipse目标平台

时间:2014-02-18 21:10:05

标签: eclipse maven osgi tycho

我有一些OSGi-bundle(普通的OSGi,没有eclipse依赖项)和一个带有pax runner的maven build,可以在Knopflerfish服务器中启动它们。

maven构建和启动捆绑包工作得非常好,但只能通过pax runner(mvn pax:provision)。

对于调试捆绑包,最好直接从eclipse中启动它们,否则我的断点不会触发(看起来很明显,因为pax:provision启动了不再与eclipse绑定的内置jar文件)。 / p>

MANIFEST.MF文件是用通常的maven-way构建的,意思是使用maven-bundle-plugin。因此,直接从eclipse启动捆绑包失败了,因为eclipse平台错过了所有需要外部OSGi捆绑的东西,而maven会让它成为maven魔法。

因此,我正在寻找一种以某种方式设置我的eclipse目标平台的方法,以便自动包含来自maven的OSGi-bundle,并且可以在IDE中访问它以在发布时解决约束。

我检查了目标平台设置,但显然只能添加特定的jar和文件夹,而不是整个文件夹结构,就像它需要使用整个本地maven存储库一样。如果我需要为每个新的依赖项更新我的目标平台,那将会变得非常难看(我希望我可以做一些像“将C:\ Users \ myprofile.m2 \ repository添加到目标平台”这样的东西,而eclipse只会加载什么它需要)。

在研究时我发现了Eclipse Tycho,但显然这只是编译用于构建bundle的目标平台,而不是用于在IDE中编译和启动它们。接下来我找到了这个网站:http://andriusvelykis.github.io/pde-target-maven-plugin/这看起来就像我需要的那样。从文档中看来,这个插件似乎能够采用从eclipse tycho编译的目标平台并将其写入文件。然后我可以将此文件导回到我的IDE中并将其用作目标平台。

我遇到的问题是,插件退出时出现了一个我无法推断的错误(我打开了堆栈跟踪以获得更完整的错误消息)。

[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

这是插件的配置:

        <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>

我可以看到路径是正确的,因为创建了platform-pde.target文件,但它与基本文件具有相同的内容。

文件内容(只是我创建并作为基本文件共享的标准目标平台):

<?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>

我正在寻找的是有关如何正确配置插件的提示或我可以将我的maven依赖包带入我的目标平台的任何其他方法,以便我可以直接从eclipse启动捆绑包,而无需在某处维护依赖关系日食偏好的深度再次出现。

2 个答案:

答案 0 :(得分:2)

您可以尝试运行PAX,为您的测试容器定义vm选项。默认情况下,容器在单独的JVM中启动,您可以为其定义命令行选项。 In the documentation甚至你会找到一个在调试模式下启动测试的例子。只需定义suspend = y,您将有足够的时间将Eclipse附加到remote debugging session

Pax Runner还有一个eclipse plugin,您可以试试。

编辑: 使用您在评论中发送的启动配置,您调试了maven JVM,而不是OSGI容器。

找到pax:provision的文档很棘手。我试过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] ------------------------------------------------------------------------

看起来如此:

  1. 创建包含以下文本的文件:

    - vmOptions = -agentlib:JDWP =运输= dt_socket,服务器= Y,暂停= Y,地址= 8888

  2. 像这样运行你的构建:

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

  3. 我没有尝试过,但它可以工作。暂停,端口8888,Eclipse远程调试:)

答案 1 :(得分:0)

我正在使用Apache Karaf进行远程调试。 karaf还从maven存储库加载bundle。 仍然eclipse找到断点并触发它们。所以同样适用于pax runner。

我所做的是导出KARAF_DEBUG = true并启动karaf。这会触发典型的远程调试设置,这些设置也应该适用于pax runner。然后我从eclipse启动一个远程调试会话,只需将所有必要的开放eclipse项目添加到远程调试会话的源代码中。这几乎在所有时间都有效。有时我的断点也没有触发,但很少见,我也没找到原因。

顺便说一下。 Karaf还允许在运行时从本地maven仓库更新捆绑包。因此,如果您更改项目,只需在单个bundle项目上调用mvn clean install,在shell上执行“update bundleid”,并继续使用新版本的bundle进行调试。当你有一个大项目但在调试时只在一小部分工作时,这非常有用。

所以要恢复你应该能够使用pax runner进行远程调试而不会出现问题,看看apache karaf可能也很有趣。