简体   繁体   English

为什么 -classpath 找不到我的 Jsoup jar 文件?

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

I am trying to run a java file that imports Jsoup classes from the command line using the following line:我正在尝试运行一个 java 文件,该文件使用以下行从命令行导入 Jsoup 类:

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 .我已经四次检查了文件路径,但它仍然找不到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:这是我要运行的 java 代码:

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.我还尝试将文件添加到 windows 系统变量,但我不确定这是否重要。

jsoup-1.8.3-javadoc.jar contains the documentation (Javadocs) for the library, and does not have any java classes in it. jsoup-1.8.3-javadoc.jar包含库的文档 (Javadocs),其中没有任何 java 类。 Instead, you should download jsoup-1.8.3.jar (eg, from https://repo1.maven.org/maven2/org/jsoup/jsoup/1.8.3/ ), and reference it in you classpath:相反,您应该下载jsoup-1.8.3.jar (例如,从https://repo1.maven.org/maven2/org/jsoup/jsoup/1.8.3/ ),并在类路径中引用它:

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

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

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