I am trying to import Jsoup using Maven but for some reason it is not seeing that it is an added dependency. I have the following code:
->Java:
import org.jsoup.Jsoup;
public class TestClass{
public static void main(String[] args) {
String url = "Google.com";
Document document = Jsoup.connect(url).get();
}
}
and
->pom.xml:
<?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>TestFile</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>
</dependencies>
</project>
When I run the java file, I get the error code “package org.jsoup does not exist. I’m not sure what the problem is.
I tried downloading Jsoup instead, and then adding it to Project Structure -> Modules, but this did not work either. I simply want the code to run without any errors.
Shai Beekman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.