Accessing Microsoft Project from Java

Java/J2EE COM Interoperability Products Page

This example demonstrates how to access Microsoft Project from Java. J-Integra® for COM is a Java interoperability component that bridges Java and Microsoft Project. It provides bi-directional access of Java objects and COM components.

We do not provide the documentation of the generated Java proxies since the Java proxies are just mapped from the programming API of the COM component. For more information about Microsoft Project programming, please refer to the Microsoft Project SDK. The quickest way to start programming Java-to-Project applications is to find a VB example first, and then map the VB code to Java.

Refer to the Excel example for the details of steps.

// This example shows a pure Java client using the J-Integra® pure Java-COM
// bridge to talk to MS Project.  You can run this program on any
// machine that supports a standard JVM.
// For information on J-Integra® and to download an evaluation copy please
// see
// Create a file called containing this
// Java code.
// Create a subdirectory called 'msproject' under the directory containing
// this Java program.  Generate the pure Java proxy files used by
// this program to access MS Project by running
// the 'com2java' tool from the J-Integra® 'bin' directory. Specify
// "\Program Files\Microsoft Office\Office\MSPRJ8.OLB"
// as the type library and "msproject" as the package name, and the
// msproject subdirectory you created above, as the output directory.

import msproject.*;

public class MSProjectExample {

  public static void main(java.lang.String[] args) throws Exception {
    try {
      // No need to do this if running under Windows, and J-Integra® 'bin' directory is in
      // your PATH.
      // com.linar.jintegra.AuthInfo.setDefault("NTDOMAIN", "username", "password");

      // Start up MS Project, and make it visible.
      // Specify host name as parameter if you wish to access MS Project remotely.
      Application app = new Application();

      // Add a new project and set its start date
      Project project = app.getProjects().add(false);
      project.setProjectStart(new java.util.Date());

      // Add a new task with a duration of ten days (assuming eight hour days)
      Task task = project.getTasks().add("MyTask", null);
      task.setDuration(new Integer(4800));

      // Display the new end date
      System.out.println("Finish Date = " + task.getFinish());

      // Wait for a bit to let the user see what is happening

      // Shut down project without saving changes

    } finally {
      // Release all remote objects that haven't already been garbage collected.