Welcome to OGeek Q&A 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...