{{< figure align=center src=“images/Create-Project-Files-in-Java-1.png.jpg” alt=“Create MS Project Files in Java”>}}

MS Project is a well-known project management application that helps managers perform project activities efficiently. Managers can create tasks, add resources, assign tasks, define timelines, and manage budgets. In some cases, they need to customize operations or automate project management in web or desktop applications.

For such cases, this article covers how to perform the basic project management operations programmatically. Particularly, you will learn how to create projects from scratch, add tasks and resources, and work with resource assignments and calendars using Java.

Java Project Management API

Aspose.Tasks for Java is a project management API that lets you create MS Project files from scratch. You can also manipulate an existing project to apply modifications. The API supports both basic and advanced project management operations. Aspose.Tasks for Java can be downloaded as JAR or installed in Maven projects with the following configuration.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-tasks</artifactId>
    <version>20.12</version>
    <classifier>jdk18</classifier>
</dependency>

Create an MS Project File using Java

MS Project can save data in MPP or XML format. Follow these steps to create an empty project file.

The following code samples show how to create an MS Project (.mpp and .xml) file using Java.

Save MS Project Files as MPP

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “create-mpp-file.java” >}}

Save MS Project Files as XML

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “create-xml-file.java” >}}

Learn more about the project manipulation features: [Working with Projects][31]

Add Tasks to a Project using Java

After creating the project file, you can add tasks to it. Follow these steps:

The following code sample shows how to add tasks to a project using Java.

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “add-task.java” >}}

Learn more about task manipulation features: [Working with Tasks][30]

Add Resources to a Project using Java

Resources are needed to perform the tasks. Follow these steps to add resources:

  • Create a new project or load an existing one using [Project][12] class.
  • Add a resource using [Project.getResources().add(String)][13] method.
  • Save the project file using [Project.save(String, SaveFileFormat)][14] method.

The following code sample shows how to add resources in a project using Java.

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “add-resource.java” >}}

Learn more about resource manipulation features: [Working with Resources][29]

Assign Tasks to Resources in a Project using Java

After adding tasks and resources, assign the tasks to the appropriate resources. Follow these steps:

  • Create a new project or load an existing one using [Project][15] class.
  • Add tasks and resources as described earlier.
  • Get references to the task and resource in [Task][16] and [Resource][17] objects.
  • Create a resource assignment using [Project.getResourceAssignments().add(Task, Resource)][18] method.
  • Save the project file using [Project.save(String, SaveFileFormat)][19] method.

The following code sample shows how to create resource assignments in a project using Java.

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “add-resource-assignment.java” >}}

Learn more about resource assignment features: [Working with Resource Assignments][28]

Add Calendars to a Project using Java

Calendars define the project timeline. Follow these steps to create a calendar:

  • Create a new project or load an existing one using [Project][20] class.
  • Create a new calendar using [Project.getCalendars().add(String)][21] method and store it in a [Calendar][22] object.
  • Use [Calendar.getWeekDays().add(WeekDay)][23] to specify weekdays.
  • Set working times in the calendar.
  • Save the project file using [Project.save(String, SaveFileFormat)][24] method.

The following code sample shows how to create a calendar in a project using Java.

{{< gist aspose-com-gists dce94bfad4682f8d9278014f7e02828b “add-calendar.java” >}}

Learn more about calendar features: [Working with Calendars][27]

Get a Free License

You can [get a free temporary license][25] to try the API without evaluation limitations.

Conclusion

In this article, you learned how to create MS Project files from scratch using Java. You saw how to add tasks, resources, resource assignments, and calendars. Explore more about the Java MS Project API in the [documentation][26].

See Also

[