I want to use docx4j in my C++ application to be able to read and write docx files.
I am trying to call a function WordprocessingMLPackage.createPackage().
First I instantiate JNI which is successful. Then get the class and method ID which are also successful. But when I try to call the function using CallStaticObjectMethod(), it fails. I tried using another Java library OpenXML4J and all functions calls executed properly. Am I missing something here? Is it something related to JAXB?
Any thoughts will be helpful. The code snippet is posted below:
// First instantiate the JVM in the following manner:
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs args;
JavaVMOption options[3];
args.version = JNI_VERSION_1_2;
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=H:\\docx4j\\docx4j-2.1.0\\docx4j.jar;"
"H:\\docx4j\\docx4j-2.1.0\\dom4j-1.6.1.jar;"
"H:\\docx4j\\docx4j-2.1.0\\log4j-1.2.13.jar;"
"H:\\docx4j\\docx4j-2.1.0\\commons-codec-1.2.jar;"
"H:\\docx4j\\docx4j-2.1.0\\commons-io-1.3.1.jar;"
"H:\\docx4j\\docx4j-2.1.0\\commons-logging-1.1.1.jar;"
"H:\\docx4j\\docx4j-2.1.0\\commons-vfs-patched-1.9.1.jar;"
"H:\\docx4j\\docx4j-2.1.0\\core-renderer-R8pre2.jar;"
"H:\\docx4j\\docx4j-2.1.0\\diffx-0.61.jar;"
"H:\\docx4j\\docx4j-2.1.0\\fop-fonts-0.2.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\hwpf-3.1.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\itext-unsigned-2.0.8.jar;"
"H:\\docx4j\\docx4j-2.1.0\\jcr-1.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\jdom-1.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\junit-4.4.jar;"
"H:\\docx4j\\docx4j-2.1.0\\minium-0.1.jar;"
"H:\\docx4j\\docx4j-2.1.0\\parent-pointer-plugin-1.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\pdf-renderer-0.2007.jar;"
"H:\\docx4j\\docx4j-2.1.0\\xalan-patched-2.7.0.jar;"
"H:\\docx4j\\docx4j-2.1.0\\xml-apis-1.0.b2.jar;"
"H:\\docx4j\\docx4j-2.1.0\\xmlgraphics-commons-1.3.jar";
args.options = options;
args.ignoreUnrecognized = JNI_TRUE;
JNI_CreateJavaVM(&jvm, (void **)&env, &args);
// Now try to make call to function Package.createPackage
jclass package = (*env).FindClass("
"org/docx4j/openpackaging/packages/WordprocessingMLPackage");
jmethodID createPackage = (*env).GetStaticMethodID(package, "createPackage",
"()Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;");
jobject mlPackage = (*env).CallStaticObjectMethod(package, createPackage);