0

I am currently developing a Java application, Maven based, using JSoup. I am using NetBeans.

This is my project structure:

enter image description here

In my pom.xml I have (I skipped the first lines):

<?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>com.mycompany</groupId>
    <artifactId>DTCCompare</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <!-- jsoup HTML parser library @ https://jsoup.org/ -->
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.14.3</version>
            <type>jar</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>DTCCompare.DTCCompareUI</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

It works perfectly from the IDE, but when I tried to run the TCDCompare.jar (.jar of my application), I got an error saying that:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jsoup/Jsoup Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup

So it looks like the jsoup.jar is not part/included in my DTCCompare.jar. I saw several posts saying that I have to perform right click on my project and Properties -> Java Build Path, click the Libraries tab, then click Add External JARs... (like in this post: Getting a java.lang.ClassNotFoundException: org.jsoup.Jsoup) However, in NetBeans when I do right click on my project, I don't have such Libraries option:
enter image description here

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
R42136
  • 33
  • 5

1 Answers1

1

That's normal: your jar does not have its dependencies.

You should either:

The later should be preferred.

NoDataFound
  • 11,381
  • 33
  • 59
  • In fact I found the answer here: https://www.journaldunet.fr/web-tech/developpement/1203063-comment-creer-un-jar-executable-avec-ses-dependances/ – R42136 Oct 23 '21 at 12:57