【问题标题】:Unable to get JIBX IBindingFactory based on binding file无法根据绑定文件获取 JIBX IBindingFactory
【发布时间】:2013-05-13 15:17:38
【问题描述】:

我使用 Eclipse 和 Maven(m2eclipse 插件)和 JIBX 来(un)编组 XML。

如果我像这样使用工厂,它会起作用:

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_bindingFactory.class下生成的,所以应该可以找到! (请记住,如果我指定一个具体的顶级绑定类,一切正常)

任何帮助将不胜感激!

我的 pom.xml 文件中的构建部分:

    <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>

【问题讨论】:

    标签: binding classnotfoundexception jibx


    【解决方案1】:

    找到了解决方案,这是getFactory(java.lang.String bname, java.lang.String pack, java.lang.ClassLoader loader)的实现中的一个错误!

    考虑第一行代码:

        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_deStub.class.getClassLoader());

    所以空引号被替换为“。”,这会导致异常:java.lang.ClassNotFoundException: .JiBX_bindingFactory 如前所述(注意类名前的点!)。

    解决方法是这样调用方法:factory = org.jibx.runtime.BindingDirectory.getFactory("binding", (String)null, ISService_1_0_deStub.class.getClassLoader()); 注意转换为字符串,否则调用不明确!

    旁注:方法getFactory(String, String)调用BindingDirectory中的getFactory(String, String, ClassLoader)方法

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多