【问题标题】:Imports cannot be resolved - Visual Studio Code for Java无法解析导入 - Visual Studio Code for Java
【发布时间】:2019-11-27 16:17:39
【问题描述】:

我正在开发一个由 Maven 管理的 Java 项目。

项目实际上由三个子项目组成: - 后端 - 生成器 - 前端

这些项目中的每一个都是基于 Maven 的,而 Builder 充当前端和后端之间的桥梁。 事实上,Builder 是所有项目的父项目。 Builderpom.xml如下:

...
<modules>
    <module>Model</module>
</modules>
...

Modelpom.xml 是这样的:

  ...
  <parent>
    <groupId>...</groupId>
    <artifactId>Builder</artifactId>
    <version>1.0.0.0</version>
  </parent>
  <artifactId>Model</artifactId>
  <build>
    *Backend build directives*      
  </build>
  ...

问题是我可以从 Visual Studio Code 成功构建每个模块而不会出错,但代码编辑器给我“import cannot be resolved..”无论我在哪里对后端有依赖性。 我开始认为这是“RedHat 的 Java 语言支持”的错误,它找不到依赖项...... 有人遇到过这种情况吗?

--- 编辑 28/11/2019 ---

我忘记说明所有 Builder 的依赖项(因此对于后端和其他 Util 库)都已正确解析,因为我可以在 Frontend's 已解析的依赖项文件夹中看到那些罐子.

【问题讨论】:

  • 您能提供代码编辑器给出的实际错误吗?
  • @Josh 实际上,对某类后端的每个依赖项都没有解决,因此它显示为错误.. 但正如我所说,maven 成功构建了一切

标签: java maven visual-studio-code


【解决方案1】:

你可以这样尝试:

在你的父项目 pom.xml 中:

<groupId>com.blackr</groupId>
<artifactId>cloudtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

在您的子项目 pom.xml 中:

<artifactId>module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>com.blackr</groupId>
    <artifactId>cloudtest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../parent/pom.xml</relativePath> //Location of the parent project's pom.xml file
</parent>

【讨论】:

  • 不幸的是,在孩子的 pom.xml 中插入标签“”并没有改变任何东西。实际上奇怪的是,我在 Builder 模块中和构建之后插入了一些依赖项前端模块我可以看到在“Maven 依赖项”中有前端模块所需的所有 Jar,因此在前端构建时可以正确解析层次结构依赖项
猜你喜欢
  • 1970-01-01
  • 2020-08-09
  • 2022-07-28
  • 2022-01-18
  • 2017-09-20
  • 1970-01-01
  • 2019-04-09
  • 2018-01-26
  • 2019-03-31
相关资源
最近更新 更多