• Post Reply Bookmark Topic Watch Topic
  • New Topic

VM can't Find main Method, but only when I Specify long class Path  RSS feed

 
Kevin Simonson
Ranch Hand
Posts: 223
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About ninety minutes ago I posted an article to the Validation Forum asking for a reference to a good Mockito tutorial, but that forum appears to be pretty low volume, so I'm posting this here. I'm trying to learn how to use Mockito. I downloaded the Mockito jar, and I can type in "jar -tf \K\Utils\mockito-1.9.5\mockito-all-1.9.5.jar" and get meaningful results, so it looks like Mockito is there okay. So I wrote the following piece of code:

Note that there's nothing about Mockito in there. I originally had references to Mockito methods in there, but after the trouble I've been having I took them out.

Anyhow, I type in "javac -cp \K\Utils\mockito-1.9.5\mockito-all-1.9.5.jar Ts.java", and it compiles just fine. Then I type in "java Ts", and it runs just fine; it prints out "Hello world!" just as you'd expect.

But then I type in "java -cp \K\Utils\mockito-1.9.5\mockito-all-1.9.5.jar Ts" and I get:

Exception in thread "main" java.lang.NoClassDefFoundError: Ts
Caused by: java.lang.ClassNotFoundException: Ts
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Ts. Program will exit.

Why am I getting different behavior when I put the long class path than what I get when I type it in without the class path? Anybody have any idea what I'm doing wrong here?

Kevin S
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Ts is in the current folder, but you didn't add the current folder to the class path. Try java -cp .;\K\<rest of cp> Ts
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin

I replied to your post about Mockito. I also moved it to the testing forum.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And before you go any further, you should always put your class in a package... you are likely to run into trouble if you don't. It isn't the cause of this error, but it could be the cause of the next one.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the system classpath yourself? It usually does more harm than good to set a classpath, so you might consider deleting it.
 
Kevin Simonson
Ranch Hand
Posts: 223
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:Because Ts is in the current folder, but you didn't add the current folder to the class path. Try java -cp .;\K\<rest of cp> Ts

This worked just fine. Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!