[MPXJ Series] Writing MS Project File using MPXJ
In the first part, we shall explore what are the different ways of writing a MS Project file using MPXJ.
Pre-requisite
The article assumes that you have downloaded MPXJ release and related dependencies. If not here are the links for download
- MPXJ - http://sourceforge.net/project/showfiles.php?group_id=70649
- Dependencies - http://mpxj.sourceforge.net/dependencies.html
Now let’s get back to the original intent of reading MPP files
Lets see the simplest form of reading an MPP file
try { ProjectWriter writer = ProjectWriterUtility.getProjectWriter("test.mpx"); ProjectFile project = new ProjectFile(); // Operations on Project File writer.write(project, "test.mpx"); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IOException ioEx) { ioEx.printStackTrace(); }
ProjectWriterUtility.getProjectWriter(fileName), provides an appropriate Reader class, based on the version of MS Project file. This is the simplest way to create a writer for an Project file. ProjectFile is the class that contains details about the Schedule, we can iterate and extract information from it. We shall discuss the details on ProjectFile in subsequent posts. ProjectWriterUtility class checks for the file extension and returns an appropriate writer.
Alternative ways
- For writing MPX file, you can use net.sf.mpxj.mpx.MPXWriter
- For writing XML Project file, use net.sf.mpxj.mspdi. MSPDIWriter

Ashish, have You tried to instanciate a Resource class?. It seems that the constructor is package private, I don’t understand the reason of this. How it’s supose that You asign a resource to a task if you can’t instanciate a resource?. Is this a bug or I’m doing something bad?.
Regards.
Ok……never mind. This is it. You can create the class Resource by calling to the addResource() method of the ProjectFile class which returns a Resource instance, then set his parameters and give his UID to the setResourceUniqueID() method of the ResourceAssignment class. By the way the this last class cannot be intanciated either (with new ()), but like the first one you can call to newResourceAssignment() in the ProjectFile class which returns a instance of ResourceAssignment.
Sorry for not realize that before, I’ve a plane learning curve.
Regards.
Ok……never mind. This is it. You can create the class Resource by calling to the addResource() method of the ProjectFile class which returns a Resource instance, then set his parameters and give his UID to the setResourceUniqueID() method of the ResourceAssignment class. By the way the this last class cannot be intanciated either (with new ()), but like the first one you can call to newResourceAssignment() in the ProjectFile class which returns a instance of ResourceAssignment.
Sorry for not realize that before, I’ve a plane learning curve…
Regards.
Actually there is a sample called MpxjCreate.java in the source directory of the package and there it shows the code for generating the resources and assignment. I didn’t see it before :P….
Regards.