简体   繁体   English

为什么IntelliJ无法找到正确的WebServlet类?

[英]Why can't IntelliJ find the correct WebServlet class?

I'm new to IntelliJ and Maven. 我是IntelliJ和Maven的新手。 I'm writing a Java class that will use the H2 database's WebServlet class. 我正在编写一个Java类,它将使用H2数据库的WebServlet类。

In my pom.xml, I've added the following to my <dependencies> section: 在我的pom.xml中,我在<dependencies>部分中添加了以下内容:

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

In my Java class, when I tell IntelliJ to resolve the symbol WebServlet , it imports javax.servlet.annotation.WebServlet instead of org.h2.server.web.WebServlet . 在我的Java类中,当我告诉IntelliJ解析符号WebServlet ,它将导入javax.servlet.annotation.WebServlet而不是org.h2.server.web.WebServlet When I try to add the import org.h2.server.web.WebServlet; 当我尝试添加import org.h2.server.web.WebServlet; statement myself, IntelliJ says it cannot resolve symbol 'h2' . 声明自己,IntelliJ说它cannot resolve symbol 'h2'

Why is IntelliJ unable to find org.h2.server.web.WebServlet ? 为什么IntelliJ无法找到org.h2.server.web.WebServlet

IntelliJ hasn't updated its internal project structure to align with the Maven project. IntelliJ尚未更新其内部项目结构来与Maven项目保持一致。 To fix this, you need to refresh the Maven project. 要解决此问题,您需要刷新Maven项目。 From the Maven Projects tool window, you can choose "Reimport All Maven Projects" (which is the button that looks like two blue arrows in a circle) and that will update the IntelliJ project with your new dependencies. 在“ Maven项目”工具窗口中,可以选择“重新导入所有Maven项目”(该按钮看起来像一个圆圈中的两个蓝色箭头),它将使用您的新依赖项更新IntelliJ项目。 If the Maven Projects tool window isn't visible, you can select View > Tool Windows > Maven Projects from the menu. 如果看不到“ Maven项目”工具窗口,则可以从菜单中选择“视图”>“工具窗口”>“ Maven项目”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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