【问题标题】:How can I use Equinox Weaving with bndtools如何将 Equinox Weaving 与 bndtools 一起使用
【发布时间】:2015-07-24 11:58:25
【问题描述】:

我如何将equinox Weavingbndtools 一起使用,因为equinox Weaving 示例太旧且无法正常工作?

更新:

尝试运行 Hello world 的编织示例时

我有两个包:

public class HelloService  implements BundleActivator {

    public void start(final BundleContext context) throws Exception {
        System.out.println("Hello world!");
    }



    public void stop(final BundleContext context) throws Exception {
        System.out.println("Good bye world!");
    }
}

bnd.bnd

-buildpath:  \
osgi.core,\
osgi.cmpn,\
biz.aQute.bnd.annotation,\
${junit}
Bundle-Version: 0.0.0.${tstamp}
Require-Bundle: helloaspect
Export-Package:  \
com.weaving.hellohistorytest
Bundle-Activator: com.weaving.hellohistorytest.HelloService

方面捆绑:

@Component
@Aspect
public class HelloAspect  {

/**
 * Replaces the "Hello world!" output with "Hi from HelloAspect ;-)".
 */
@Before("execution(* HelloService+.*(..))")
public void advice() {
   System.out.println("hello aspect");
}
}

bnd.bnd

-buildpath:  \
osgi.core,\
osgi.cmpn,\
biz.aQute.bnd.annotation,\
${junit},\
aspectjrt-1.7.3,\
aspectjweaver,\
org.eclipse.equinox.supplement
Bundle-Version: 0.0.0.${tstamp}
Service-Component:  \
    *
Export-Package:  \
com.weaving.helloaspect;aspects="HelloAspect"

Eclipse-SupplementBundle: com.weaving.hellohistorytest

launch.bndrun

runbundles:  \
org.apache.felix.gogo.runtime,\
org.apache.felix.gogo.shell,\
org.apache.felix.gogo.command,\
org.eclipse.equinox.weaving.aspectj,\
org.eclipse.equinox.weaving.hook,\
aspectjweaver,\
aspectjrt-1.7.3,\
osgi.cmpn,\
osgi.core,\
cnf.run.equinox.common,\
org.apache.felix.framework,\
osgi.enterprise,\
org.eclipse.equinox.supplement,\
    helloaspect;version=latest,\
hellohistorytest;version=latest,\

-runproperties:\
osgi.framework.extensions=org.eclipse.equinox.weaving.hook


 -runrequires:\
 osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
 osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'

-runvm: -Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook,\
-Daj.weaving.verbose=true,\
-Dorg.aspectj.weaver.showWeaveInfo=true,\
-Dorg.aspectj.osgi.verbose=true

当我运行启动时: 我得到你好世界而不是你好方面 还有,Aspect Weaving Hooks Plug-in (Incubation) 设置已解决

有什么问题?

【问题讨论】:

  • 还是没有得到任何帮助
  • 建议进行(确保 Aspect 在每个步骤之后仍在运行)(1)尝试从 git repo 中获取示例(3.x 或 4.x)。 (2) 移除其他环境 (3) 移除其他方面(只保留您想要使用的那个) (4) 添加您的包 (5) 调整方面以修改您的包非常整洁。这就是为什么我提供了GitHub repo
  • @PeterKirschner。感谢您的帮助。为什么如果我在int x,y,z; public AfterAspect(int _x,int _y,int _z){ x=_x; y=_y; z=_z; } 之前在@After("execution (* example.aspectj.app.Application.methodToModify(..))") public void methodAfter(JoinPoint joinPoint) 之前添加一个构造函数,它会打印启动AspectJ 演示应用程序 使用参数 "Hi RCP World! 调用 methodToModify 3 次而不进入 methodAfter 内部方面 ??

标签: osgi aspectj equinox load-time-weaving bndtools


【解决方案1】:

可以在GitHub 上找到一个有效的源代码示例

一般情况下,here 的说明也适用于 bndtools。

添加所需的捆绑包

-runbundles: \
  org.eclipse.equinox.weaving.aspectj,\
  org.aspectj.runtime,\
  org.aspectj.weaver

确保 org.eclipse.equinox.weaving.hook 位于同一位置

-runpath: org.eclipse.equinox.weaving.hook

您需要在 *.bndrun 中提供以下运行属性

-runproperties:\
   osgi.framework.extensions=org.eclipse.equinox.weaving.hook

以下运行时属性可选择用于调试。请注意,即使它们正常工作,输出也会始终转到 std.err 流)。

aj.weaving.verbose=true,\
org.aspectj.weaver.showWeaveInfo=true,\
org.aspectj.osgi.verbose=true,\

【讨论】:

  • 谢谢@Peter Kirschner。我尝试了你的步骤,但是当我启动 OSGI 时,它从示例中打印“Hello World”而不是“来自 HelloAspect 的 Hi”。我应该将 aop.xml 包含在 -includeresource在 bnd 中?。我仍然无法让它工作。你能给我一个使用 bndtools 运行的完整示例吗?
  • 我尝试让我的旧示例(Eclipse 3.8)使用 Eclipse Mars 或 Luna 作为 IDE。面临奇怪的问题。将在旧环境中尝试一下。本周更新。
  • 感谢@Peter Kirschner。我希望这周能找到更新,并提供一个使用 bndtools 的工作示例。
  • 。非常感谢您的帮助,我会试一试。
  • @Peter Kirschner:当我运行 3.10.x_explicit.bndrun 时,我得到:org.aspectj.weaver.tools.Jdk14Trace 错误严重:寄存器定义失败 example.aspectj.bnd.app] 警告寄存器定义失败 - (RuntimeException) 无法注册非方面:example$aspectj$explicit$AfterAspectJ example.aspectj.explicit.AfterAspectJ
猜你喜欢
  • 2012-07-29
  • 1970-01-01
  • 2018-11-12
  • 2014-03-04
  • 2014-10-26
  • 2021-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多