MS Project is a well-known project management application that makes it easier for managers to perform project management activities efficiently. The project managers can create tasks, add resources, and assign tasks to the resources within a particular project. Furthermore, they can define the timeline as well as perform budget management operations. However, there could be various scenarios when managers need to customize project management operations. Also, an organization may need to automate project management within 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
- Create an MS Project File from Scratch using Java
- Add Tasks to a Project
- Add Resources to a Project
- Assign Tasks to Resources in a Project
- Add Calendars to a Project
- Get Free License
Java Project Management API
Aspose.Tasks for Java is a project management API that lets you create MS Project files from scratch. Furthermore, you can manipulate an existing project in order to add some modifications. The API lets you perform basic as well as advanced project management operations seamlessly. Aspose.Tasks for Java can be downloaded as JAR or installed within Maven-based applications using the following configurations.
<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 allows you to save the project-related data in either MPP or XML format. So let’s start with creating an empty project file by following the below steps.
- Create an instance of Project class.
- Save the file using Project.save(String, SaveFileFormat) method.
The following code samples show how to create an MS Project (.mpp and .xml) file using Java.
Save MS Project Files as MPP
Save MS Project Files as XML
Learn more about the project manipulation features: Working with Projects
Add Tasks to a Project using Java
After creating the project file, you can start adding the tasks to it. The following are the steps to create and add tasks to a project file.
- Create an instance of Project class.
- Add a new summary task to the project’s tasks collection using Project.getRootTask().getChildren().add(string) method.
- Add a subtask to the summary task using Task.getChildren.add(string) method.
- Save the project file using Project.save(String, SaveFileFormat) method.
The following code sample shows how to add tasks to a project using C#.
Learn more about task manipulation features: Working with Tasks
Add Resources to a Project using Java
The next important thing in a project is the resources that will be assigned to perform the tasks. So in this section, we’ll add some resources to the project. The following are the steps to add resources to the project.
- Create a new project or load an existing one using Project class.
- Add resource using Project.getResources().add(String) method.
- Save the project file using Project.save(String, SaveFileFormat) method.
The following code sample shows how to add resources in a project using Java.
Learn more about resource manipulation features: Working with Resources
Assign Tasks to Resources in a Project using Java
Once you have added the tasks and resources, the next thing is to assign the tasks to the relevant resources. The following are the steps to perform resource assignments in a project.
- Create a new project or load an existing one using Project class.
- Add tasks and resources in the same way you have added in the previous sections.
- Get references to the task and resource in a Task and Resource object respectively.
- Create a resource assignment using Project.getResourceAssignments().add(Task, Resource) method.
- Save the project file using Project.save(String, SaveFileFormat) method.
The following code sample shows how to create resource assignments in a project using Java.
Learn more about resource assignment features: Working with Resource Assignments
Add Calendars to a Project using Java
Calendars are another important entity that is used to define the timeline of a project. Using the calendar, you can create a complete schedule for a project. In order to create a calendar, you can follow the below steps:
- Create a new project or load an existing one using Project class.
- Create a new calendar using Project.getCalendars().add(String) method and get its reference in Calendar object.
- Use Calendar.getWeekDays().add(WeekDay) method to specify the weekdays.
- Set working times in the calendar.
- Save the project file using Project.save(String, SaveFileFormat) method.
The following code sample shows how to create calendar in a project using Java.
Learn more about calendar features: Working with Calendars
Get a Free License
You can get a free temporary license in order to try the API without evaluation limitations.
Conclusion
In this article, you have learned some basic features of how to create MS Project files from scratch using Java. Particularly, you have seen how to add tasks, resources, resource assignments, and calendars in a project. You can explore more about the Java MS Project API using documentation.