I'm trying to explore webscraping in Java and am just starting with a very basic Jsoup program to get started. I am pretty sure there is some sort of path issue with what I am doing. I have tried different variations, and just to get it working have simplified the process by including the library in the same directory as my source file(to simplify the path while I figure out what is going on). Here is what I have been doing and the output:
javac -cp jsoup-1.7.3.jar URLParse.java
The above compiles with no errors(it also compiled fine when I had the jar in its own folder and specified the path), the below happens when I try to run the program:
java -cp jsoup-1.7.3.jar URLParse.java
Exception in thread "main" java.lang.NoClassDefFoundError: URLParse/java
Caused by: java.lang.ClassNotFoundException: URLParse.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: URLParse.java. Program will exit.
The following is the code in case it help:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class URLParse{
public static void main(String[] args){
String URL = "http://www.google.com";
try{
Document doc = Jsoup.connect(URL).get();
System.out.println("Ok here");
String title = doc.title();
System.out.println(title);
} catch (IOException e){
e.printStackTrace();
}
}
}
Thanks for any help or suggestions.