Question

I am trying to open Microsoft Word document using jacob.

Below is code:

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class openWordDocument {
    private static final Integer wdNewBlankDocument = new Integer(0);
    private static final Variant vTrue = new Variant(true);
    private static final Variant vFalse = new Variant(false);
    private static ActiveXComponent activeXWord = null;
    private static Object activeXWordObject = null;

    public static void main(String[] args) {
    try {
    activeXWord = new ActiveXComponent("Word.Application");
    activeXWordObject = activeXWord.getObject();
    Dispatch.put(activeXWordObject, "Visible", vTrue);

    //activeXWordObject = null;

    }
    catch (Exception e) {
    quit();
    }
    }

    public static void quit() {
    if (activeXWord != null) {
    System.out.println("quit word");
    //calls the Quit method of MS Word, this will close MS Word
    activeXWord.invoke("Quit", new Variant[] {});
    ComThread.Release();
    activeXWord.release();
    System.out.println("quit word");
    }
    }

}

When I am running above code getting error Error: Could not find or load main class openWordDocument

Was it helpful?

Solution

It's my mistake, I added .dll file in the classpath so I am unable to compile the java file. I removed that dll file after that, jvm started compiling and able to fine the class file.

OTHER TIPS

Warning !!!

Check your external libraries (such as .jar files) path were added to to your project. The path should have regular format. For example it supposed to not have special characters like as "+", ... or space.

I had that serious problem before in Eclipse IDE, change the path directory of my project library and then everything is okay again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top