如何将 Equinox Weaving 与 bndtools 一起使用

How can I use Equinox Weaving with bndtools

我如何将 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

当我 运行 启动时: 我得到 Hello world 而不是 hello aspect 此外,Aspect Weaving Hooks 插件(孵化)已设置已解决

有什么问题?

可以在 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,\