5

I am trying to familiarize myself with Eclipse's support for Java 9 modules. I use Eclipse Oxygen with the Java 9 Support Package from the marketplace and the latest JDK 9 u180.

The problem concerns module dependencies and how to let Eclipse know about them.

My understanding is that in Eclipse a JPMS module corresponds to an Eclipse project. I created three projects aka modules and added the necessary module-info files:

module com.effjava.app {
  requires com.effjava.support;
}

module com.effjava.support {
  exports com.effjava.support.hlp;
  exports com.effjava.support.test;
  exports com.effjava.support.user;

  requires transitive com.effjava.util;
}

module com.effjava.util {
  exports com.effjava.util.cbk;
  exports com.effjava.util.reg;
}

It is a simple top-down dependency chain. The module descriptors are correct; I already succeeded in setting up the same modules in IntelliJ.

My problem is: how do I tell Eclipse that the top modules depend on the bottom ones, e.g. that the middle module com.effjava.support depends on the bottom module com.effjava.util?

I did specify the dependency in the module-info file (via requires transitive) and Eclipse accepts the directive without a complaint. Yet I see an error message when I compile the middle module com.effjava.support. The error message says that a public type from package com.effjava.util.cbk is not visible, despite being exported by module com.effjava.util and required by module com.effjava.support.

screenshot showing project structure and compiler error message

In order to specify the dependency, I exported the content of the bottom module com.effjava.util to a jar file, including the module-info.class. Hence it is a modular jar file.

Then I imported the modular jar file into the com.effjava.support module and added the imported modular jar file to the build path. To no avail.

screenshot of build path

I tried it without an import, just adding the modular jar as an external library. It didn't work either.

The question is: how do I correctly specify module dependencies in Eclipse?

1
  • The details of this are still work in progress. For now it's probably best to let your Projects explicitly depend on each other via Java Build Path > Projects (this is partly redundant with module-info, but since modules are not versioned you probably need a build system to manage your dependencies anyway). OTOH, the errors in your screenshot look bogus. If this happens with latest from the marketplace (1.1.1.v20170731-0938_BETA_JAVA9) please file a bug at bugs.eclipse.org/bugs/… Aug 4, 2017 at 9:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.