Maven project compile error: cannot find symbol (which is java.lang.String)

3573 views java intellij-idea maven
7

It's a very simple web scraping program that I built in intellij idea with the maven build system. It worked fine before today but when I tried to build it today it gave me object not found errors for base java objects like String and List. When I tried to reload the maven project I got another error below. Idea also highlights the basic java object in red and gives no advice. The only thing I did was slightly modify the java source code. So, I tested with the stock hello world code. It did compile and run, but Intellij still highlights String and System in red and the maven reload produces the same error. Help is greatly appreciated as I need to get some data for a research project.

Error with web scraping source code compilation error

Error:(24, 13) java: cannot find symbol
  symbol:   class List
  location: class Main

Maven reload error

Cannot resolve plugin org.apache.maven.plugins:maven-compiler-plugin:${maven.compiler.version}

This is the pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>htmlunittest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>net.sourceforge.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>2.19</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.7.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

answered question

go to intellij menu File -> project structure -> project setting - > select your JDK

Unfortunately, that's not the problem. JDK is 11.

@T0m4t0s4uc3 Did you try adding this to ur pom ?

put your main class here

2 Answers

3

Update:

After resolving the maven errors, since you are facing IDE related problems, I would suggest you to do this:

  1. Go to File > Project Structure

IntelliJ1

  1. Add the JDK in Project SDK

IntelliJ2


You have forgot to define the property ${maven.compiler.version} in your POM.

Define a properties section in your POM like this:

  <properties>
    <java.version>1.11</java.version>
    <maven.compiler.version>3.8.1</maven.compiler.version>
  </properties>

posted this
6

You have to select JDK in Intellij

Go to intellij menu File -> project structure -> project setting - > select your JDK in project SDK section

posted this

Have an answer?

JD

Please login first before posting an answer.