简体   繁体   中英

referencing another project in eclipse

  1. I created project A with package name "A"

  2. I created another project called "B"

  3. Properties->Java Build Path->Modulepath
    added "A"

  4. project B has a source file with "import A" statement

I get "The package A is not accessible"

Option 1: You have the package or the project A stored into another folder. Option 2: You've deleted A or any content related with A so it's not there anymore

That you have added the project to the modulepath and not to the classpath means that you are using Java Platform Module System ( JPMS ) : each of the two projects contains the file module-info.java in the default package .

You have two options:

  • In the module-info.java files do the following:
    • Project A must export the packages that you want to use in project B:
      In module-info.java of project A add for each exported package a line
      exports <package-to-export>;
    • In project B the dependency to the module of project A must be defined:
      In module-info.java of project A add the line
      requires <project-A-module-name>;
  • Delete both module-info.java files (in most cases this is the recommended solution)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM