首页 > 解决方案 > 项目找不到类

问题描述

我正在编写一个 Java 项目来了解 JPA 和 JDBC。eclipse 中的项目被称为WSShop& 访问另一个名为 的 eclipse 项目JPAUtilities,其中包含一个名为的类,该类JPAUtils使用一个EntityManager类。

我的问题是,虽然使用的项目没有问题,但JPAUtilities使用EntityManagerWSShop项目JPAUtilities发现问题EntityManager并给出错误消息

Description Resource    Path    Location    Type
The project was not built since its build path is incomplete. Cannot find the class file for javax.persistence.EntityManager. Fix the build path then try building this project WSShop      Unknown Java Problem
The type javax.persistence.EntityManager cannot be resolved. It is indirectly referenced from required .class files JPAUserDAO.java /WSShop/src/main/java/com/example/demo  line 35 Java Problem

以下是项目和子项目的设置:

<code>WSShop</code> 属性 <code>JPAUtilities</code> 属性

我将java.persistenceJAR 添加到WSShop项目中,但仍然得到相同的错误:

<code>WSShop</code> 项目中的代码有错误

但是JPAUtilities被 使用WSShop,但JPAUtilities没有任何问题(WSShop在此处关闭):

<code>JPAUtilities</code> 代码与已关闭的 <code>WSShop</code> 项目

我究竟做错了什么?

<code>WSShop</code> 包含的子项目

谢谢您的帮助!

编辑: 我检查了pom.xml& 将错误减少到三个。现在,EntityManager不再是问题了。POM 文件包含以下几行:

        <dependency>
        <groupId>org.springframework.boot.autoconfigure</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <version>2.1.7.RELEASE</version>
    </dependency>

存在…\.m2\repository\org\springframework\boot\spring-boot\2.1.7.RELEASE带有spring-boot-2.1.7.RELEASE可执行 Jar 文件的目录。我改变了项目的配置如下

WSShop 的新 Java 构建路径

…现在是错误和警告

新的错误和警告

标签: javaeclipse

解决方案


推荐阅读