pacoverflow
pacoverflow

Reputation: 3891

Why can't IntelliJ find the correct WebServlet class?

I'm new to IntelliJ and Maven. I'm writing a Java class that will use the H2 database's WebServlet class.

In my pom.xml, I've added the following to my <dependencies> section:

    <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. When I try to add the import org.h2.server.web.WebServlet; statement myself, IntelliJ says it cannot resolve symbol 'h2'.

Why is IntelliJ unable to find org.h2.server.web.WebServlet?

Upvotes: 1

Views: 1729

Answers (1)

Zeus
Zeus

Reputation: 231

IntelliJ hasn't updated its internal project structure to align with the Maven project. To fix this, you need to refresh the Maven project. 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. If the Maven Projects tool window isn't visible, you can select View > Tool Windows > Maven Projects from the menu.

Upvotes: 1

Related Questions