I realize this is probably a very simple question, but I have been researching it for literally days on end to no avail. Any help would be much appreciated.
My project structure looks like this:
src
|--Main.java
|--WebScrapper.java
out
|--Main.class
|--WebScrapper.java
lib
|--Jsoup
My WebScrapper.java file imports the Jsoup library utilities like this:
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Element;
I am using a Java library in my project on the InteliJ IDE. In the IDE I go to "Project Structure -> Modules -> Add Jars or Directories" and my program works by me selecting the "run" button in IntelliJ, however when I compile the Java code, and try to run it with "java Main.class" from the terminal, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at WebScrapper.returnPage(WebScrapper.java:12)
at Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
I know that this is a problem with the library and not my other class file, because when I changed the other class file to a simple System.out.printl statement, it works perfectly fine. How do I get this dependency to work in my project? Do I need to create a lib folder and do something? Or is it something else? I have browsed many other questions on stack overflow, and have seen solutions like cleaning the build, using a dependency management plugin like maven etc. However, rebuilding the project did not work and I would like to avoid using a dependency management system if possible, however if needed I will do so.
Thanks in advance, Michael