Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

java - NoSuchMethodError: org.docx4j.org.apache.xml.serializer.SerializerFactory.getSerializer

Maven Dependency

<dependency>
            <groupId>de.phip1611</groupId>
            <artifactId>docx4j-search-and-replace-util</artifactId>
            <version>1.0.3</version>
        </dependency>

<dependency>
        <groupId>org.docx4j</groupId>
        <artifactId>docx4j</artifactId>
        <version>6.1.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

My Code is look like this as mentioned below.

 WordprocessingMLPackage sourceDocxDoc = WordprocessingMLPackage.load(fileInputStream) ;
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 HashMap<String, String> replace = new HashMap<String, String>();
 replace.put("$Tag1","My Db Data");
 .
 .
 .
 .
 .
 .
 Docx4JSRUtil.searchAndReplace(sourceDocxDoc, replace);
 sourceDocxDoc.save(out);

program runs successfully on local environment but sometimes getting exception on production environment as per attached image on line sourceDocxDoc.save(out);

I can't debug it on local environment, so anyone else experienced this issue while using Docx4j lib to replace MS Word file contains identifier with data.

Java Experts kindly respond.............

Exception Image

Same issue found at this link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Issue is resolved by my self

instead of using below maven dependency

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>6.1.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I changed to below maven dependency and it works.

<dependency>
        <groupId>org.docx4j</groupId>
        <artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
        <version>8.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.docx4j</groupId>
        <artifactId>docx4j-core</artifactId>
        <version>8.1.0</version>
        <scope>compile</scope>
    </dependency>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...