【问题标题】:Add maven dependencies of OSGi bundles to the Eclipse target platform将 OSGi 包的 maven 依赖项添加到 Eclipse 目标平台
【发布时间】:2014-03-18 21:24:21
【问题描述】:

我有一些 OSGi 捆绑包(普通 OSGi,没有 Eclipse 依赖项)和一个带有 pax runner 的 maven 构建,可以在 Knopflerfish 服务器中启动它们。

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

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

MANIFEST.MF 文件以通常的 maven 方式构建,即使用 maven-bundle-plugin。因此,直接从 eclipse 启动捆绑包失败,因为 eclipse 平台错过了所有需要的外部 OSGi 捆绑包,而 maven 得到了它的 maven 魔法。

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

我检查了目标平台设置,但显然只能向其中添加特定的 jar 和文件夹,而不是像使用整个本地 maven 存储库所需的整个文件夹结构。如果我需要为每个会变得非常丑陋的新依赖项更新我的目标平台(我希望我可以执行类似“将 C:\Users\myprofile.m2\repository 添加到目标平台”之类的操作,而 Eclipse 只会加载什么它需要)。

在研究时,我发现了 Eclipse Tycho,但显然这只编译了一个用于构建捆绑包的目标平台,而不是用于从 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 启动包,而无需在某处维护依赖项再次深入了解日食偏好。

【问题讨论】:

    标签: eclipse maven osgi tycho


    【解决方案1】:

    您可以尝试运行 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=transport=dt_socket,server=y,suspend=y,address=8888

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

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

    我没有尝试过,但它可以工作。挂起,端口 8888,Eclipse 远程调试 :)

    【讨论】:

    • 我尝试了远程调试,我的断点仍然没有触发 - 我想你可以调试由 pax 直接启动的内容,但不能调试由 pax 启动的部署到 osgi 服务器的包(但我可能是错的,这只是我想出的解释)。使用 eclipse 插件我又遇到了同样的问题 - 它取决于 OSGi 启动配置,我再次遇到相同的编译器问题,因为无法解决 maven 依赖项。
    • 当您使用 Eclipse 进行远程调试时,您定义了一个要调试的项目。如果您将 jar 添加到调试配置的“类路径”中,其中包含具有断点的类,或者您的调试项目已经在其类路径中,则应触发断点。
    • 这是启动pax的maven build命令的设置:pl.vc/1ivd6这是远程调试的设置:pl.vc/3l7ly不管我用suspend=y还是suspend=n, maven build 监听连接,调试器连接但我在指定项目中设置的断点没有被触发。这就是为什么我开始寻找替代解决方案的原因,但如果它能够以这种方式工作当然也很好。
    • 非常感谢,这成功了!然后我对为什么我的调试尝试不起作用的假设是正确的,但我没有设法找到那篇文档。
    【解决方案2】:

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

    我所做的是导出 KARAF_DEBUG=true 并启动 karaf。这会触发典型的远程调试设置,这些设置也应该可用于 pax runner。然后我从 Eclipse 启动一个远程调试会话,并简单地将所有必要的打开的 Eclipse 项目添加到远程调试会话的源中。这几乎一直有效。有时我的断点也没有触发,但很少,我没有找到原因。

    顺便说一句。 Karaf 还允许在运行时从本地 maven repo 更新包。因此,如果您更改项目,您可以简单地在单个包项目上调用 mvn clean install,在 shell 上执行“更新 bundleid”,然后可以继续使用新版本的包进行调试。当您有一个大型项目但在调试时只工作一小部分时,这非常有用。

    所以要恢复,您应该能够毫无问题地使用 pax runner 进行远程调试,并且看看 apache karaf 也可能很有趣。

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 1970-01-01
      • 2012-11-28
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 2011-02-22
      • 2012-01-20
      相关资源
      最近更新 更多