redhat-developer / redhat-developer/vscode-java

supposed compilation errors when using java 17 modules in visual studio code

未关闭
#3,376 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

upstream
主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
11

描述

Environment
  • Operating System: windows 11
  • JDK version: "17.0.7" 2023-04-18 LTS
  • Visual Studio Code version: 1.84.0 user setup
  • Java extension version: v.0.25.15

When I create the following code I get a compilation error saying that certain packages do not exist. The steps I followed are:

1. create a project in java in my case it is called OCP JAVA 17

2. create a folder called 12. Modules (within this folder is the directory with program codes and modules written in Java 17)

3. create a folder called feeding

4. inside the feeding folder, create a module-info.java file with the following code
module zoo.animal.feeding {
    exports zoo.animal.feeding;
}
5. inside the feeding folder, create a package or folders in the following order zoo/animal/feeding and add the Task.java file with the following code
package zoo.animal.feeding;

public class Task {
    public static void main(String... args) {
        System.out.println("All fed!");
    }
}
6. compile Task.java class and module-info.java with following command in terminal opening from 12.Modules folder
   javac -p
   mods -d
   feeding
   feeding/zoo/animal/feeding/Task.java feeding/*.java

7. create a folder called mods and run the following command in the terminal to package our compiled code from the 12.Modules folder
   jar -cvf
   mods/zoo.animal.feeding.jar -C
   feeding/ .

8. run the program by entering the following command in the terminal from 12.Modules
   java -p
   mods
   -m
   zoo.animal.feeding/zoo.animal.feeding.Task
   must be printed in console All fed!

9. create a folder called care with the following file module-info.java with the code
module zoo.animal.care {
    exports zoo.animal.care.medical; //here is vsc supposed compilation error

    requires zoo.animal.feeding;
}
10. inside the care folder create 2 packages/folders in the following order zoo/animal/care/details and zoo/animal/care/medical

11. in the zoo/animal/care/details package add the following file HippoBirthday.java
// HippoBirthday.java
package zoo.animal.care.details;

import zoo.animal.feeding.*;

public class HippoBirthday {
    private Task task;
    public static void main(String... args) { //mio
        System.out.println("Feliz cumple"); //mio
    }
}
12. in the zoo/animal/care/medical package add the following Diet.java file
// Diet.java
package zoo.animal.care.medical;

public class Diet {
    public static void main(String... args) { //mio
        System.out.println("Diet"); //mio
    }
}
13. compile and package what is inside the care folder, in the terminal from 12.Modules with the following command
    javac -p
    mods
    -d
    care
    care/zoo/animal/care/details/_.java
    care/zoo/animal/care/medical/_.java
    care/module-info.
    java

jar -cvf mods/zoo.animal.care.jar -C care/ . 14) run the classes that are inside the zoo.animal.care.medical package (which vsc says does not exist) in terminal from 12.Modules java -p mods -m zoo.animal.care/zoo.animal.care.medical.Diet the word Diet should be printed in the console

If the program runs properly, there should be no reason for vsc to mark an error in red, such as in the module-info.java file in the care folder that says that the package zoo.animal.care.medical does not exist. Your help please

attached screenshots

imagen imagen

VS Code version: Code 1.84.0 (d037ac0, 2023-11-01T11:29:04.398Z) OS version: Windows_NT x64 10.0.22621 Modes:
System Info
Extensions (15)
A/B Experiments

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用所示的 module-info.java、Task.java、HippoBirthday.java 和 Diet.java 文件,以及列出的 javac、jar 和 java 命令,复现该报告。将终端中成功的编译与 care/module-info.java 上的红色诊断进行比较,然后追踪 Java 扩展如何处理这种模块布局。当有效 package 不再被报告为缺失,或者在该诊断符合预期的情况下,问题已有文档化解释时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, vscode
领域
developer-experience, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。