To add jsoup (Java HTML Parser) to your Java project, you can do so by including it as a dependency in your project’s build configuration file or by downloading and adding the jar file to your project's classpath directly. Below are the instructions for each method:
Using Maven
If you're using Maven, you can add jsoup as a dependency in your pom.xml
file. Add the following dependency block to your pom.xml
within the <dependencies>
section:
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.2</version> <!-- Replace with the latest version -->
</dependency>
When you build your project, Maven will automatically download the jsoup library and its dependencies.
Using Gradle
For Gradle, add the following line to your build.gradle
file in the dependencies
block:
implementation 'org.jsoup:jsoup:1.15.2' // Replace with the latest version
Gradle will handle the rest during the next build or sync.
Manual Download and Installation
If you are not using a build system like Maven or Gradle, you can manually download the jsoup jar file and include it in your project's classpath.
- Go to the jsoup website's download page: https://jsoup.org/download
- Download the latest release of the jsoup jar file.
- Place the downloaded jar file in a
lib
directory within your project (you may need to create this directory if it doesn't exist). - Add the jar file to your project's classpath. The way to do this varies depending on the IDE or build system you are using. Here's how you might do it in some common IDEs:
- Eclipse: Right-click on the project > Properties > Java Build Path > Libraries tab > Add JARs... > Select the jsoup jar file you placed in the
lib
folder. - IntelliJ IDEA: File > Project Structure > Modules > Dependencies tab > "+" > JARs or directories > Select the jsoup jar file you placed in the
lib
folder.
Command Line Compilation
If you are compiling your Java files from the command line, you will need to include the path to the jsoup jar file in the -cp
(classpath) option:
javac -cp ".:path/to/jsoup-1.15.2.jar" YourJavaFile.java
And to run your application:
java -cp ".:path/to/jsoup-1.15.2.jar" YourMainClass
Note: On Windows, replace the colon (:
) with a semicolon (;
) in the classpath.
Remember to check https://jsoup.org/download for the latest version of jsoup and replace the version numbers in the above examples accordingly.