0

I'm on Windows and I have a java class file called WebCrawler.class located inside a folder. Also in this folder is a jar file called commons-validator-1.6.jar, and WebCrawler uses functionality from that jar file. WebCrawler is part of a package called cloud.simplecrawl. I navigate to that folder via command line and compile with:

javac -cp commons-validator-1.6.jar WebCrawler.java

Compilation happens just fine.

Then, I want to run that program, WebCrawler.class, but I can't figure out the exact syntax for the java call, and I feel like I've tried everything. I know it should be some form of:

java -cp <something here?> commons-validator-1.6.jar Webcrawler

But I can't figure it out! Please help!

Tyler M.
  • 115
  • 1
  • 1
  • 11
  • Please read: [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – Turing85 Jan 19 '20 at 20:30
  • Does `java -cp commons-validator-1.6.jar WebCrawler` not work for you? – Slaw Jan 19 '20 at 20:31
  • @Slaw No, unfortunately it doesn't! I get the error "Could not find or load main class WebCrawler" – Tyler M. Jan 19 '20 at 20:32
  • Is `WebCrawler.class` in the working directory? Does `WebCrawler` have a package? – Slaw Jan 19 '20 at 20:34
  • Yes, it is in the working directory. WebCrawler.java, WebCrawler.class, and commons-validator-1.6.jar are all in the working directory. This directory is called "simplecrawl". I did declare a package, and my working directory is the tail-end of that package: cloud.simplecrawl, and WebCrawler is in that package. – Tyler M. Jan 19 '20 at 20:36
  • The package is cloud.simplecrawl and the directory path that I'm in is \src\cloud\simplecrawl and all of those files are in that directory. – Tyler M. Jan 19 '20 at 20:37
  • You may need to set the working directory so that `cloud/simplecrawl/WebCrawler.class` is the relative path to that class file. Then you can try `java -cp path/to/commons-validator-1.6.jar cloud.simplecrawl.WebCrawler`. – Slaw Jan 19 '20 at 21:09
  • So, essentially, I need to "back out" to the starting directory of the package? – Tyler M. Jan 19 '20 at 21:20
  • @Slaw I tried that, so now I'm in a folder that contains commons-validator-1.6.jar. Also inside this folder is a folder called cloud, inside of which is a folder called simplecrawl, and in THAT folder is WebCrawler.java. I compiled everything and it works fine, but running it still says "could not find or load main class cloud.simplecrawl.WebCrawler" when I use the command you suggested. – Tyler M. Jan 19 '20 at 21:25
  • 1
    @Slaw I figured it out! I had to back out, like you said, but then the command needed to be: java -cp .\;commons-validator-1.6.jar cloud.simplecrawl.WebCrawler Thank you! You got me there. – Tyler M. Jan 19 '20 at 21:35

0 Answers0