Why won't -classpath find my Jsoup jar file?

Viewed 297

I am trying to run a java file that imports Jsoup classes from the command line using the following line:

javac -classpath "C:\Users\gtdub\JSOUP\jsoup-1.8.3-javadoc.jar;." JsoupTester.java

The type of errors I see are:

JsoupTester.java:1: error: package org.jsoup does not exist

I have quadruple checked the file path and it still will not locate jsoup-1.8.3-javadoc.jar. Is the command line statement I'm using wrong? Here is the java code I am trying to run:

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupTester {
   public static void main(String[] args) {
   
      String html = "<html><head><title>Sample Title</title></head>"
         + "<body><p>Sample Content</p></body></html>";
      Document document = Jsoup.parse(html);
      System.out.println(document.title());
      Elements paragraphs = document.getElementsByTag("p");
      for (Element paragraph : paragraphs) {
            System.out.println(paragraph.text());
      }
   }
}

I also tried adding the file to the windows system variables but I am not sure if that matters.

1 Answers

jsoup-1.8.3-javadoc.jar contains the documentation (Javadocs) for the library, and does not have any java classes in it. Instead, you should download jsoup-1.8.3.jar (e.g., from https://repo1.maven.org/maven2/org/jsoup/jsoup/1.8.3/), and reference it in you classpath:

javac -classpath "C:\Users\gtdub\JSOUP\jsoup-1.8.3.jar;." JsoupTester.java
Related