无法基于绑定文件获取JIBX IBindingFactory
我将Eclipse与Maven(m2eclipse插件)和JIBX一起使用,以(联合)marshall XML 如果我像这样使用工厂,它会起作用:无法基于绑定文件获取JIBX IBindingFactory,binding,classnotfoundexception,jibx,Binding,Classnotfoundexception,Jibx,我将Eclipse与Maven(m2eclipse插件)和JIBX一起使用,以(联合)marshall XML 如果我像这样使用工厂,它会起作用: IBindingFactory bindingFactory=BindingDirectory.getFactory(mappedClass) 但是,我希望基于绑定文件创建一个工厂,因为这是由自动生成的服务存根完成的。因此,我在TestNG中运行了以下测试: @Test public void testBindingFactory() {
IBindingFactory bindingFactory=BindingDirectory.getFactory(mappedClass)代码>
但是,我希望基于绑定文件创建一个工厂,因为这是由自动生成的服务存根完成的。因此,我在TestNG中运行了以下测试:
@Test
public void testBindingFactory() {
try
{
IBindingFactory factory = BindingDirectory.getFactory("binding", "");
} catch (JiBXException e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
并且它会失败,并显示以下错误消息:
Unable to access binding 'binding'
Make sure classes generated by the binding compiler are available at runtime
java.lang.ClassNotFoundException: .JiBX_bindingFactory
名称(文件名为binding.xml)是正确的,空的“”表示没有包,这也是正确的,但我想可能是个问题
工厂是在我的项目文件夹中的target/classes/JiBX\u bindingFactory.class
下生成的,所以应该可以找到它!(记住,如果我指定了一个具体的顶级绑定类,那么一切都可以正常工作)
任何帮助都将不胜感激
mypom.xml文件中的build部分:
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.5</version>
<configuration>
<schemaBindingDirectory>src/main/config</schemaBindingDirectory>
<includeSchemaBindings>
<includeSchemaBinding>binding.xml</includeSchemaBinding>
</includeSchemaBindings>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<!-- Do we require other goals? http://jibx.sourceforge.net/maven-jibx-plugin/ -->
<goal>bind</goal>
<!-- goal>test-bind</goal-->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
org.jibx
jibxmaven插件
1.2.5
src/main/config
binding.xml
真的
绑定
找到了解决方案,这是getFactory(java.lang.String bname、java.lang.String pack、java.lang.ClassLoader)实现中的一个错误。
考虑代码的前几行:
public static IBindingFactory [More ...] getFactory(String bname, String pack,
ClassLoader loader) throws JiBXException {
String cname = (pack == null ? "" : pack + '.') +
GENERATE_PREFIX + convertName(bname) + BINDINGFACTORY_SUFFIX;
...
请记住,自动生成的服务存根称为getFactory方法,如下所示:factory=org.jibx.runtime.BindingDirectory.getFactory(“binding”),“”,
ISService_1_0_desub.class.getClassLoader())代码>
因此,空引号被替换为“.”,这导致异常:java.lang.ClassNotFoundException:.JiBX_bindingFactory
(注意类名前的点!)
解决方案是调用如下方法:factory=org.jibx.runtime.BindingDirectory.getFactory(“binding”,(String)null,
ISService_1_0_desub.class.getClassLoader())代码>
注意转换为字符串,否则调用是不明确的
StEnoTo:方法GETFACKE(String,String)调用BIDENGISTION/P>USER778199中的方法GETFACKE(String,String,ClassLoader),您应该考虑在JBX bug中提交一个谢谢!