2014-09-11 32 views
2

在部署我的項目到Tomcat服務器,我不斷地得到這個異常:包名犯規包含ObjectFactory.class或jaxb.in​​dex

產生的原因:org.springframework.beans.factory.BeanCreationException:錯誤創建與豆名稱'marshaller':調用init方法失敗;嵌套的異常是org.springframework.oxm.UncategorizedMappingException:未知的JAXB異常;嵌套異常是javax.xml.bind.JAXBException:「be.icredit.einvoice.proxy.customerdaoservice」不包含ObjectFactory.class或jaxb.in​​dex

但它確實有一個ObjectFactory.class!

即時通訊使用Spring,Maven和JAXB2

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

我從字面上一無所知..

我的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> 
+0

你有沒有加入生成的類來源?請參閱[鏈接](http://stackoverflow.com/a/25600373/3364187) – Xstian 2014-09-11 11:48:50

+0

否..爲什麼這是必需的?我的項目通過Maven Install構建,這很好。沒有編譯器錯誤? – 2014-09-11 11:55:47

+0

生成的類將在目標文件夾下創建。如果要使用它們,則必須通過之前通過您的鏈接添加到源文件夾。 「build-helper-maven-plugin」 – Xstian 2014-09-11 11:59:34

回答

2

首先,讓我們檢查您是否遇到Maven構建或IDE中的問題。

你是說你的構建似乎很好。

  • 你有一個簡單的解組測試,它檢查解組真正起作用嗎?做一個,並確保它的工作。
  • 檢查生成的war - 它是否具有所有生成的類WEB-INF/classes
  • 你有幾個執行過程,那裏是所有生成的包(在WEB-INF/classes)?

當排除Maven構建問題時,請檢查您的IDE。我想你使用的是Eclipse:

  • 您是否將所有生成的目錄看作Eclipse源文件夾?
  • 您的簡單解組測試(請參閱上文)是否可以在Eclipse中使用?
  • 您是否必須以某種方式配置哪些文件夾部署到Tomcat?
  • 您是否需要將編譯目標重定向到WEB-INF/classes

有相當多的地方可能會出錯。一個簡單的單元測試將幫助檢查每一步,找出缺少的東西。

正如我之前所說,maven-jaxb2-plugin確實會將您的目標目錄添加爲編譯源代碼根目錄(除非您明確地將其配置爲您不需要的目標目錄)。因此,Eclipse中的m2eclipse等Maven集成插件應該將這些目錄添加爲源文件夾。您的項目與「正常」設置有點不同,因爲您有一個war項目和多個執行。但我仍然認爲這必須工作,maven-jaxb2-plugindoes pretty standard stuff here

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

這正是build-helper-maven-plugindoes相同:

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