我有一个OSGi包含持久性服务(使用hibernate)和一个片段的包,其中包含配置(xml文件).在bundle的激活器中,我使用以下命令加载配置:
@Override
public void start(BundleContext ctx) {
URL url = ctx.getBundle().getResource("hibernate.cfg.xml");
SessionFactory sessionFactory = new AnnotationConfiguration().configure(url).buildSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
但有时候,这URL是空的.当我试图列出所有可用的URLs(使用findEntries方法)时,看起来捆绑包自己的那些总是可用,但有时只是片段.我正在使用Felix4.0.2,捆绑包和片段是在同一个地方启动的Felix.auto.start级别.
我正在使用JNotify项目来监听文件系统事件.这取决于每个OS的一个本机库:处理器架构.例如,有一个用于Windows x86的库,一个用于x86-64等的库.
最初,我有一个包含JNotify Java类和本机代码的包.本机代码在Bundle-NativeCode中声明如下:
(我已经将这些格式化为bnd样式以获得更好的可读性......显然,实际的MANIFEST.MF文件已正确形成).
Bundle-NativeCode: jnotify_64bit.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname= Windows8;osname = WindowsServer2012;processor = x86-64,\
jnotify.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname = Windows8;osname = WindowsServer2012;processor = x86,\
libjnotify.so;osname = Linux;processor = x86,\
libjnotify64.so;osname = Linux;processor = x86-64,\
libjnotify.dylib;osname = Mac OSX;processor = x86;processor = x86-64,\
*
Run Code Online (Sandbox Code Playgroud)
这很好用.
我认为如果我将库移动到单独的片段包中会很"好",这样我就可以为我感兴趣的体系结构贡献片段.以Linux为例,我将它们分成两个包:
Linux 32位
Include-Resource: lib/libjnotify.so
Bundle-NativeCode: libjnotify.so;osname = Linux;processor …Run Code Online (Sandbox Code Playgroud) 我有一个依赖于它的实现包和片段包(MANIFEST中的Fragment-Host).此外,还有一些测试包.
现在我想测试我的实现并使用tycho-surefire-plugin.带有测试的bundle通过MANIFEST中的Require-Bundle引用实现包.到现在为止还挺好.问题是如何将片段包放入测试运行时?我在我的eclipse-test-plugin中尝试了tycho-surefire-plugin配置中的依赖.但它不起作用.什么是正确的方法?
编辑:我的测试插件的pom.xml
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<testSuite>com.example.impl.tests</testSuite>
<testClass>com.example.impl.tests.MyTest</testClass>
<dependencies>
<dependency>
<type>eclipse-plugin</type>
<artifactId>com.example.impl.config</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
片段包的清单:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.example.config
Bundle-SymbolicName: com.example.config
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: example
Fragment-Host: com.example.impl;bundle-version="1.0.0.qualifier"
Bundle-ClassPath: resources/
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Run Code Online (Sandbox Code Playgroud)
从反应器pom.xml中提取:
<modules>
<module>../com.example.impl</module>
<module>../com.example.impl.config</module>
<module>../com.example.impl.tests</module>
</module>
Run Code Online (Sandbox Code Playgroud)
谢谢!
似乎只有一个这种性质的其他问题,在这里,但这个答案提出解决方案并没有得到有效的我.我使用Spring Tool Suite(本质上是Kepler 4.3.2 SR2)作为我的IDE来开发包含最新版本的一些本机C++代码的OSGi片段.存在片段以允许存在于该本机代码旨在与其集成的不同环境中的不同版本的软件的可能性.
但是我无法导出此片段,显然是因为我们用来表示此版本号的自定义vm arg.
清单看起来像这样:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Windows 64-bit support for Third-Party XYZ 4.12.7
Bundle-SymbolicName: com.ourcompany.oursoftwarepackage.xyz.win64xyz4127
Bundle-Version: 8.6.2.qualifier
Bundle-Vendor: OurCompany
Fragment-Host: com.ourcompany.oursoftwarepackage.xyz
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86_64))
Bundle-NativeCode: xyzintegration.dll; selection-filter = "(oursoftwarepackage.xyzVersion=4.12.7)"
Bundle-ClassPath: .
Run Code Online (Sandbox Code Playgroud)
错误说:
处理包含来自org.eclipse.pde.container.feature的功能:Bundle com.ourcompany.oursoftwarepackage.xyz.win64xyz4127_8.6.2.qualifier无法解析:不满意的本机代码过滤器:xyzintegration.dll; 选择过滤器= "(oursoftwarepackage.xyzVersion = 4.12.7)".
如果我删除选择过滤器子句然后它似乎导出但没有产生实际的工件.
我从上面的链接推断的建议是包括vmarg
-Doursoftwarepackage.xyzVersion=4.12.7
Run Code Online (Sandbox Code Playgroud)
在插件开发目标环境中.但是,这似乎并不满足OSGi框架.现在我不知道如何解决片段以便导出可以继续.
我有一个插件,它是片段A和B的主机.我使用片段A中的Export-Package头导出包.希望我可以使用Import-Package头在片段B中导入该包.但PDE报告说依赖关系尚未解决.完全可以使用这种情况吗?以下文章http://www.eclipse.org/forums/index.php/t/238204/确认它是.
任何帮助将不胜感激.
感谢和问候,
Setya
在OSGi API中,对BundleContext.getBundles()的调用将返回所有包,无论它们是否为片段.对于给定的Bundle对象,判断这是否是片段的最佳方法是什么?
启动情况(无任何错误):
现在,我使捆绑包 B 成为捆绑包 A(片段主机)的片段,并在捆绑包 B 的 MANIFEST 中添加指令 Fragment-Host: org.apache.xmlbeans
进行此更改后,所有捆绑包(A、B、C)的 MANIFEST.MF 中都没有错误,但捆绑包 CI 的类 .java 中出现编译错误:“导入 com.prova.xsd.config 无法已解决”与文件 .java 头部的导入相关联。
问题是什么?我该如何修复它?
多谢,
安德里亚
我正在尝试使用片段插件将补丁应用于现有插件,如下所述:
主机插件的补丁包括用更新的类文件替换单个类文件。但是我在“ 修改主机程序包清单设置步骤5)到11)中没有得到这个概念。在这里,它指示您修改主机插件。我认为整个想法是,您不必触摸主机插件-它部署的片段会添加补丁?
我的产品包括eclipse平台和org.eclipse.cdt功能,以及我自己使用cdt的插件。我要修补的是org.eclipse.cdt.core插件。
我已按照Eclipse Wiki中的步骤进行操作,并创建了我的片段项目,其中包含要在主机插件中修补的包和类。我是在Maven中构建的,当我运行该产品时,我看到我的片段插件处于活动状态,但是其中包含的类没有被调用;原始的主机插件类是。
我猜问题是修改后的主机插件不在我部署的产品中。片段指南中没有包含有关部署主机插件的建议的任何步骤,而且我不确定是否需要/为什么。
(过去,我已经成功使用了功能补丁,但只能使用PDE创建-我无法在Maven下构建功能补丁-这就是为什么我探索使用片段来查看如果我可以让他们在Maven下进行构建。)
更新*:我使用Tycho插件创建Maven的构建版本Tycho-使用maven构建Eclipse插件。
感谢您链接到“ OSGi Core Release 5规范”。那很有用。
因此,如果我的理解是正确的,那么如果主机插件已经“准备好”使用片段进行修补,则片段只能将其类覆盖在主机插件上。这涉及修改主机插件的清单。具体来说:1.添加一个新库,并将其移到“。”上方。包。从构建属性中删除该库;该库仅供参考,不应由主机插件创建。+在manifest.mf文件中添加Eclipse-ExtensibleAPI:true +增加版本号。
就我而言,如果我想使用片段修补org.eclipse.cdt.core插件,我将不得不交付org.eclipse.cdt.core插件的预备版本以及我的片段插件。
*:不确定礼节;没有足够的声誉去做很多事情。注释框仅接受少量字符。
我有一个带有多个插件的Eclipse RCP项目.我正在编写简单的JUnit测试(不依赖于Eclipse/UI)作为测试插件的单独片段.
当使用Mockito并尝试从另一个插件模拟一个接口(正确导出;我可以在我的代码中使用该接口)时,我得到一个与类签名相关的SecurityException:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface ch.sbb.polar.client.communication.inf.service.IUserService
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
[...]
Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
[...]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
Caused by: java.lang.SecurityException: Signers of 'ch.sbb.polar.client.communication.inf.service.IUserService$$EnhancerByMockitoWithCGLIB$$a8bfe723' do not match signers of other classes in package
at java.lang.ClassLoader.checkPackageSigners(ClassLoader.java:361)
at java.lang.ClassLoader.defineClass(ClassLoader.java:295)
... 40 more
Run Code Online (Sandbox Code Playgroud)
当我将测试作为"JUnit插件测试"运行时,即使用OSGi环境,一切都按预期工作.但是我想因速度而使用普通的JUnit执行; 在被测试的类中,我不需要OSGi环境.
有人知道这样做的方法吗?
我想org.eclipse.swt为片段创建一个扩展.我创建了一个swt.extension包含以下MANIFEST.MF 的包:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Extension
Bundle-SymbolicName: swt.extension
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.swt;bundle-version="3.102.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Run Code Online (Sandbox Code Playgroud)
另外,我创建了一个从SWT扩展接口的接口:
public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {
}
Run Code Online (Sandbox Code Playgroud)
当我使用tycho(mvn clean install)构建项目时,会发生以下错误:
1. ERROR in C:\<path>\tycho-fragment-to-fragment-dependency\swt.extension\src\org\example\tycho_example\IExtendedStyleTextContent.java (at line 3)
public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {
^^^^^^^^^^^
org.eclipse cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud)
似乎tycho只解析了org.eclipse.swt jar.这是一个主机包,它不包含任何类.实际的实现是在org.eclipse.swt.win32.win32.x86_64片段包中.当tycho-compiler-plugin编译项目时,看起来这个bundle不在classpath上.
这是第谷的错误吗?他们有任何变通方法吗?
我把所有资源放在GitHub上:https://github.com/orionll/tycho-fragment-to-fragment-dependency
我使用maven 3.1.0
osgi-fragment ×10
osgi ×6
java ×3
eclipse ×2
eclipse-rcp ×2
maven ×2
tycho ×2
bundle ×1
eclipse-cdt ×1
equinox ×1
junit ×1
mockito ×1
native-code ×1
patch ×1