ClassNotFoundException:org.apache.xml.serialize.XMLSerializer

問題

Exception in thread "main" java.lang.RuntimeException:
    Could not instantiate serializer org.apache.xml.serialize.XMLSerializer:
    java.lang.ClassNotFoundException: org.apache.xml.serialize.XMLSerializer
    at org.exolab.castor.xml.XercesSerializer.<init>(XercesSerializer.java:50)
   //...

MavenのCastor依存性。

    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor</artifactId>
        <version>1.2</version>
    </dependency>

解決策

間違いでない場合、 CastorはXercesを動作させる必要がある ので、Xerces依存関係も追加する必要があります。

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.castor</groupId>
            <artifactId>castor</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.8.1</version>
        </dependency>

    </dependencies>