我有一些 OSGi bundle (普通 OSGi,没有 Eclipse 依赖项)和一个带有 pax runner 的 Maven 构建,可在 Knopflerfish 服务器中启动它们。
maven 构建和启动 bundle 工作得很好,但只能通过 pax runner (mvn pax:provision
)。
为了调试 bundle ,最好直接从 Eclipse 中启动它们,否则我的断点将不会触发(似乎很明显,因为 pax:provision 启动不再与 Eclipse 绑定(bind)的构建的 jar 文件)。
MANIFEST.MF 文件是按照通常的 maven 方式构建的,意味着使用 maven-bundle-plugin。因此,直接从 Eclipse 启动 bundle 会失败,因为 Eclipse 平台错过了 Maven 发挥其 Maven 魔力所需的所有外部 OSGi bundle 。
因此,我正在寻找一种方法来以某种方式设置我的 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 启动包,而无需在某个位置维护依赖项再次深入了解 Eclipse 偏好设置。
最佳答案
您可以尝试通过为测试容器定义 vm 选项来运行 PAX。默认情况下,容器在单独的 JVM 中启动,您可以为其定义命令行选项。 In the documentation甚至您会找到一个在 Debug模式下启动测试的示例。只需定义 suspend=y,您就有足够的时间将 remote debugging session 附加到您的 Eclipse 上。 。
还有一个eclipse plugin对于 Pax Runner,您可以尝试一下。
编辑: 使用您在评论中发送给我的启动配置,您调试了 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] ------------------------------------------------------------------------
看起来是这样:
创建一个包含以下文本的文件:
--vmOptions=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8888
像这样运行你的构建:
mvn pax:provision -Dargs=file:///c:/yourfilepath/thefile containsstuffabove.txt
我没有尝试过,但它可以工作。挂起,端口 8888,Eclipse 远程调试:)
关于eclipse - 将 OSGi 包的 Maven 依赖项添加到 Eclipse 目标平台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21865383/