Free Java API to Generate & Manipulate Project MPP & MPX Files

Open Source library that enables software developers to read and write project data in various file formats, read project plans, perform data analysis and generate reports inside Java Apps.

In the dynamic world of project management, efficient handling of project data is crucial for success. One powerful tool that has been gaining recognition in this domain is the MPXJ library. Developed by Jon Iles, MPXJ is an open-source Java library that provides a set of facilities to read and write project data in various file formats. In this article, we'll explore the features and capabilities of the MPXJ library, shedding light on how it can enhance project management processes.

MPXJ supports the Microsoft Project Exchange (MPX) file format and enables seamless integration with Java applications. It allows users to read and write project data in formats such as MPP, MPX, and XML, making it a versatile solution for diverse project management needs. The library provides a high level of abstraction, simplifying the handling of complex project structures and tasks. It is designed to be platform-independent, ensuring that it can be easily integrated into various Java-based projects across different operating systems.

One of the standout features of the MPXJ library is its support for multiple project file formats. Whether you're working with Microsoft Project files or using XML-based formats, MPXJ allows for smooth import and export of project data. The library provides a rich set of APIs for manipulating project data. Developers can extract, modify, and analyze project information programmatically, empowering them to automate repetitive tasks and streamline project management processes. It stands out as a reliable and versatile solution, offering a range of features for reading, writing, and manipulating project data. With its cross-platform compatibility and extensive file format support, MPXJ empowers developers to build efficient and customized project management solutions.

Previous Next

Getting Started with MPXJ

First of all, you need to have the Java Development Kit (JDK) installed on your system. Referencing MPXJ in your Maven-based Java project is even simpler. All you need is to add the following dependency in your pom.xml and let your IDE fetch and reference the MPXJ Jar files.

MPXJ Maven Dependency



<dependencies>
<dependency>
<groupId>net.sf.mpxj</groupId>
<artifactId>mpxj</artifactId>
<version>10.11.0</version>
</dependency>
</dependencies>

You can download the directly from GitHub page

Reading & Writing Project Data via Java API

The open source MPXJ library allows users to effortlessly read and write project data from different file formats such as MPP (Microsoft Project), MPX, and XML. The library has included support for multiple project file formats. Whether you're working with Microsoft Project files or using XML-based formats, MPXJ allows for smooth import and export of project data. Here's an example of how you can read a Microsoft Project file (.mpp) and extract task information.

How to Read a Microsoft Project File (.MPP) & Extract Task Information via Java API?

import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.reader.ProjectReader;
import net.sf.mpxj.reader.UniversalProjectReader;

public class ReadMPPExample {
    public static void main(String[] args) {
        try {
            ProjectReader reader = new UniversalProjectReader();
            ProjectFile project = reader.read("sample.mpp");
            
            System.out.println("Project Name: " + project.getProjectProperties().getName());
            System.out.println("Tasks:");
            project.getTasks().forEach(task -> {
                System.out.println("ID: " + task.getID() + ", Name: " + task.getName());
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Data Analysis and Reporting

MPXJ enables users to perform data analysis and generate reports based on project information. It can be utilized to automate the generation of project reports by extracting relevant data from project files. This can save time and ensure accuracy in reporting processes. Developers can leverage the library to build custom project management tools that align with the unique needs of their organizations. This flexibility allows for the creation of tailored solutions that enhance overall project efficiency. Here's an example demonstrating how to calculate the total duration of tasks in a project.

How to Calculate the Total Duration of Tasks in a Project via Java API?

import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.Task;

public class DataAnalysisExample {
    public static void main(String[] args) {
        try {
            ProjectFile project = new ProjectFile("sample.mpp");
            int totalDuration = 0;
            
            for (Task task : project.getTasks()) {
                totalDuration += task.getDuration();
            }
            
            System.out.println("Total duration of tasks: " + totalDuration + " days");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
           

Simplified Data Manipulation

With MPXJ library, working with project data becomes a breeze. Whether its extracting task information, updating resource allocations, or generating reports, MPXJ offers a comprehensive set of APIs to perform a myriad of operations, empowering developers to automate and streamline project management tasks efficiently. Here's an example demonstrating how to create a new task and add it to a project.

How to Create a New Task and Add It to a Project via Java API?

import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.Task;

public class ManipulateProjectExample {
    public static void main(String[] args) {
        try {
            ProjectFile project = new ProjectFile();
            Task task = project.addTask();
            task.setName("New Task");
            task.setDuration(5); // duration in days
            
            System.out.println("New task added to the project.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}