Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.
Module dependency refers to one module being dependent on or requiring another module. Module dependencies were introduced in the Declaring Dependency on Other Modules section in the article “Developing a Module with Java 9 in Eclipse IDE, Part 1.” In the first of two articles, “Using Module Dependencies, Part 1,” we created two Java projects for two modules, a main module and a dependency module. We couldn’t have created both modules in one Java project because the Eclipse IDE does not support multiple modules in a single project. Having created two projects, in this continuation article we shall export each project to a separate JAR file. Exporting and using a module as a JAR file is discussed in an earlier tutorial, “Using a Java 9 Module as a JAR File.” Adding multiple modules in a single JAR is not currently supported, but is planned for a future Java version. In this article, we shall discuss configuring the two Java projects and running the main module application to demonstrate module dependency. This article has the following sections:
Setting the Build Path of the Main Java Project
The two Java projects previously developed have errors, as indicated by the red markers in Figure 1. The errors are indicated because the two modules are defined in separate projects and the dependency project is not in the build path of the main project.
In this section, we shall configure the build path for the MainModule project to add the HelloJavaModule project to the build path. Right-click MainModule in Package Explorer and select Build Path>Configure Build Path, as shown in Figure 2.