0

I use Eclipse with Maven (m2eclipse plugin) and JIBX to (un)marshall XML.

It works if I use the factory like this:

IBindingFactory bindingFactory = BindingDirectory.getFactory(mappedClass);

However I want to create a factory based on the binding file, because this is done by the automatically generated service stub. So I run the following test in TestNG:

    @Test
public void testBindingFactory() {
    try
    {
        IBindingFactory factory = BindingDirectory.getFactory("binding", "");
    } catch (JiBXException e)
    {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

and it fails with the following error message:

    Unable to access binding 'binding'
    Make sure classes generated by the binding compiler are available at runtime
    java.lang.ClassNotFoundException: .JiBX_bindingFactory

The name (filename is binding.xml) is correct, the empty "" means no package, which is also correct, but could be a problem I guess?

The factory is generated under target/classes/JiBX_bindingFactory.class in my project folder, so it should be found! (Remember everything works if I specify a concrete toplevel binded class)

Any help would be appreciated!

The build section in my pom.xml file:

    <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>
user2378199
  • 1
  • 1
  • 1

1 Answers1

0

Found the solution, its a bug in the implemention of getFactory(java.lang.String bname, java.lang.String pack, java.lang.ClassLoader loader)!

Consider the first lines of code:

    public static IBindingFactory  [More ...] getFactory(String bname, String pack,
    ClassLoader loader) throws JiBXException {

    String cname = (pack == null ? "" : pack + '.') +
        GENERATE_PREFIX + convertName(bname) + BINDINGFACTORY_SUFFIX;
    ...

Remember that the auto-generated service stub called the getFactory method like this: factory = org.jibx.runtime.BindingDirectory.getFactory("binding", "", ISService_1_0_deStub.class.getClassLoader());

So the empty quotes are replaced with ".", which leads to the Exception: java.lang.ClassNotFoundException: .JiBX_bindingFactory as said (note the dot before the class name!).

The solution is to call the method like this: factory = org.jibx.runtime.BindingDirectory.getFactory("binding", (String)null, ISService_1_0_deStub.class.getClassLoader()); Note the cast to String, otherwise the call is ambiguous!

Sidenote: The method getFactory(String, String) calls the method getFactory(String, String, ClassLoader) in BindingDirectory

user2378199
  • 1
  • 1
  • 1
  • user2378199, You should consider filing a JiBX bug at http://jira.codehaus.org/secure/BrowseProject.jspa?id=10410 Thanks! – Don Corley May 14 '13 at 16:56