packagename doesnt contain ObjectFactory.class or jaxb.index

Kornelito Benito picture Kornelito Benito · Sep 11, 2014 · Viewed 7.4k times · Source

While deploying my project to a tomcat-server, I get constantly this exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marshaller': Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: "be.icredit.einvoice.proxy.customerdaoservice" doesnt contain ObjectFactory.class or jaxb.index

But it does have an ObjectFactory.class!

Im using Spring, Maven and Jaxb2

My POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>be.icredit</groupId>
    <artifactId>einvoice</artifactId>
    <packaging>war</packaging>
    <name>einvoice Portlet</name>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <liferay.maven.plugin.version>6.2.10.6</liferay.maven.plugin.version>
        <liferay.version>6.2.1</liferay.version>
        <spring.suite.version>3.2.10.RELEASE</spring.suite.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>com.liferay.maven.plugins</groupId>
                <artifactId>liferay-maven-plugin</artifactId>
                <version>${liferay.maven.plugin.version}</version>
                <executions>

                </executions>
                <configuration>
                    <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                    <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                    <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                    <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                    <liferayVersion>${liferay.version}</liferayVersion>
                    <pluginType>portlet</pluginType>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.9.0</version>

                <executions>
                    <execution>
                        <id>BatchDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/batchdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>BatchDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.batchdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>CustomerAccountDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/customeraccountdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>CustomerAccountDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.customeraccountdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>CustomerDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/customerdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>CustomerDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.customerdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>DocumentDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/documentdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>DocumentDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.documentdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>DocumentTemplateDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/documenttemplatedaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>DocumentTemplateDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.documenttemplatedaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>EmailStatusDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/emailstatusdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>EmailStatusDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.emailstatusdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>EmailTemplateDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/emailtemplatedaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>EmailTemplateDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.emailtemplatedaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>FileService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/fileservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>FileService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.fileservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>SenderDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/senderdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>SenderDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.senderdaoservice</generatePackage>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>portal-service</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-bridges</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-taglib</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-java</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

I am literally clueless..

My applicationcontext:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:annotation-config />
    <context:component-scan base-package="be.icredit.einvoice.service, be.icredit.einvoice.webserviceTest" />


    <oxm:jaxb2-marshaller id="marshaller" contextPath="be.icredit.einvoice.proxy.customerdaoservice"/>
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
         <property name="marshaller" ref="marshaller" /> 
         <property name="unmarshaller" ref="marshaller" /> 
        <property name="defaultUri"
            value="http://localhost:8081/ws-demo/account-balance-service" />
    </bean>

</beans>

Answer

lexicore picture lexicore · Sep 11, 2014

First of all, let's check if you have the problem with the Maven build or in the IDE.

You're saying that your build seems to work fine.

  • Do you have a simple unmarshalling test which checks that unmarshalling really works? Make one and make sure it works.
  • Check the generated war - does it have all of the generated class in WEB-INF/classes?
  • You have several executions, are all of the generated packages present there (in WEB-INF/classes)?

When problems with the maven build are ruled out, check your IDE. I think you're using Eclipse:

  • Do you see all of the generated directories as Eclipse source folders?
  • Does your simple unmarshalling test (see above) work in Eclipse?
  • Do you have to configure somehow, which folders are deployed to Tomcat?
  • Do you maybe need to redirect compilation target to WEB-INF/classes?

There's quite a couple of places this can go wrong. A simple unit test will help check every step to find out what's missing.

As I said before, maven-jaxb2-plugin does add your target directory as a compile source root (unless you explicitly configure it out which you don't do). So Maven integration plugins like m2eclipse in Eclipse are supposed to add these directories as source folders. Your project is a bit different from the 'normal' setup in a sense that you have a war project and multiple executions. But I still think this must work, maven-jaxb2-plugin does pretty standard stuff here:

    if (getAddCompileSourceRoot()) {
        getProject().addCompileSourceRoot(getGenerateDirectory().getPath());
    }

This is exactly the same what build-helper-maven-plugin does:

this.project.addCompileSourceRoot( source.getAbsolutePath() );