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

Categories

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...