• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: Could not find or load main class - run from CMD  RSS feed

 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

When I run my class file from CMD I got the error:

java YahooLoginGheckoDriver.class
Error: Could not find or load main class YahooLoginGheckoDriver.class

The java command I run form the directory where there is my class file.

I am trying to put name of package and I receive the same error:

Error: Could not find or load main class yahoologingheckodriver.YahooLoginGheckoDriver.class

From IDE my file is running.



 
Henry Wong
author
Sheriff
Posts: 23028
120
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dana Ucaed wrote:
When I run my class file from CMD I got the error:

java YahooLoginGheckoDriver.class
Error: Could not find or load main class YahooLoginGheckoDriver.class


The JVM can't fine the "class" class in the YahooLoginGheckoDriver package... which is probably not what you intended. The parameter passed to the JVM is the fully qualified name of the class, with the main() method -- and not the name of the class file.

Henry
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same error when I write name of package:


D:\prjAutJava\YahooLoginGheckoDriver\build\classes\yahoologingheckodriver>java yahoologingheckodriver.YahooLoginGheckoDriver.class
Error: Could not find or load main class yahoologingheckodriver.YahooLoginGheckoDriver.class

The source file is in another directory.

 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I tried with dependency:

D:\prjAutJava\YahooLoginGheckoDriver\build\classes\yahoologingheckodriver>java  -jar D:\Proiecte\selenium-java-2.47.1\selenium-2.47.1\selenium-server-standalone-3.4.0.jar D:\prjAutJava\YahooLoginGheckoDriver\build\classes\yahoologingheckodriver\YahooLoginGheckoDriver.YahooLoginSuccess.class
Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter 'D:\prjAutJava\YahooLoginGheckoDriver\build\classes\yahoologingheckodriver\YahooLoginGheckoDriver.YahooLoginSuccess.class' but no main parameter was defined
        at com.beust.jcommander.JCommander.getMainParameter(JCommander.java:914)
        at com.beust.jcommander.JCommander.parseValues(JCommander.java:759)
        at com.beust.jcommander.JCommander.parse(JCommander.java:282)
        at com.beust.jcommander.JCommander.parse(JCommander.java:265)
        at com.beust.jcommander.JCommander.<init>(JCommander.java:210)
        at org.openqa.grid.selenium.GridLauncherV3$1.setConfiguration(GridLauncherV3.java:227)
        at org.openqa.grid.selenium.GridLauncherV3.buildLauncher(GridLauncherV3.java:155)
        at org.openqa.grid.selenium.GridLauncherV3.main(GridLauncherV3.java:75)
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, for an simple java file without no dependency I have the same result.

D:\PrjJava\OCA7\Converion\src\converion>java converion.Converion.class
Error: Could not find or load main class converion.Converion.class

D:\PrjJava\OCA7\Converion\src\converion>dir
Volume in drive D has no label.
Volume Serial Number is 2255-DECD

Directory of D:\PrjJava\OCA7\Converion\src\converion

06/12/2017  05:19 PM    <DIR>          .
06/12/2017  05:19 PM    <DIR>          ..
06/12/2017  05:19 PM               674 Converion.class
06/09/2017  03:03 PM               600 Converion.java
               2 File(s)          1,274 bytes
               2 Dir(s)  43,444,228,096 bytes free

 
Dave Tolls
Ranch Hand
Posts: 2560
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Henry is saying is you are putting in the class file.
You need to use the class name, which is yahoologingheckodriver.YahooLoginGheckoDriver in your case, (note the lack of '.class' there).

But in order for that to run you need to be in the directory above the one you are in.  That is, the directory containing the yahoologingheckodriver directory.
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange.

I tried but the same result:

D:\PrjJava\OCA7\Converion\src\converion>java converion.Converion
Error: Could not find or load main class converion.Converion

 
Henry Wong
author
Sheriff
Posts: 23028
120
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dana Ucaed wrote:
D:\PrjJava\OCA7\Converion\src\converion>java converion.Converion
Error: Could not find or load main class converion.Converion


In this case, you are trying to use the Converion class, that is in the converion package. Is the class actually declared that way?

And do you have a class path set?  If not, then do you have the class file located in the "D:\PrjJava\OCA7\Converion\src\converion\converion" directory? Can you run a "dir" listing of it for us?

Henry
 
Norm Radder
Rancher
Posts: 1772
26
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D:\PrjJava\OCA7\Converion\src\converion>java converion.Converion
Error: Could not find or load main class converion.Converion

Is there a Converion.class file in the converion folder?
Is that class in the converion package?

If so you must have the classpath point to to folder that contains the converion folder.
The default classpath is in the current directory.

Either set the classpath to the src folder
or change directory to the src folder and  use the command:  java converion.Converion
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
D:\PrjJava\OCA7\Converion\src\converion>java converion.Converion
Error: Could not find or load main class converion.Converion

Is there a Converion.class file in the converion folder?
Is that class in the converion package?

If so you must have the classpath point to to folder that contains the converion folder.
The default classpath is in the current directory.


Norm Radder wrote:

Either set the classpath to the src folder
or change directory to the src folder and  use the command:  java converion.Converion


Yes,  there is a Converion.class in conversion folder.

I changed to src folder and I have the same error.

Probably PATH and CLASSPATH aren't correctly set.



 
Norm Radder
Rancher
Posts: 1772
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed to src folder and I have the same error.

Please copy the contents of the command prompt window and paste it here so we can see what command was issued and what directory it was in.

What about this question:
Is that class in the converion package?

Probably PATH and CLASSPATH aren't correctly set.

If PATH were wrong the java command would not be found.

If CLASSPATH is set, you need to give the classpath to the java command: java -cp . converion.Converion
when in the src folder.

Note: You should be sure the CLASSPATH value includes the . for the current directory
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my classpath I don't have .

D:\PrjJava\OCA7\Converion\src>echo %PATH%
C:\Program Files\Java\jdk1.8.0_131\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;D:\Kit\Junit;C:\Program Files (x86)\Java\bin;C:\Program Files\Git\cmd;C:\Users\andad\AppData\Local\Microsoft\WindowsApps;

D:\PrjJava\OCA7\Converion\src>echo %CLASSPATH%
D:\POI3.15\poi-3.15\poi-3.15.jar;D:\POI3.15\poi-3.15\poi-ooxml-3.15.jar;D:\POI3.15\poi-3.15\poi-ooxml-schemas-3.15.jar;D:\POI3.15\poi-3.15\poi-scratchpad-3.15.jar;D:\Documentatie\HTMlunit\htmlunit-2.27\lib;D:\Documentatie\selenium-remote-driver-2.42.1.jar;D:\Proiecte\selenium-java-2.47.1\selenium-2.47.1\selenium-server-standalone-3.4.0.jar;D:\Proiecte\HTMLunit\cssparser-0.9.23.jar;C:\Users\andad\Documents\eclipse\plugins\org.hamcrest.core_1.3.0.v201303031735.jar;C:\Users\andad\Documents\eclipse\plugins\org.junit_4.11.0.v201303080030\junit.jar;D:\Documentatie\Maven\apache-maven-3.5.0\bin;D:\Documentatie\Selenium\java-json.jar\java-json.jar;D:\prjAutJava\YahooLoginGheckoDriver\build\classes\yahoologingheckodriver;D:\PrjJava\OCA7\Converion\src\converion;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar


I am using Windows 10 and Java 8.
 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Norm.  You save me.

I think that my problem is that is am not set . in my classpath.

What agitation!

I watch on all video on YouTube regarding path and classpath.

From my IDE all are OK.

 
Dana Ucaed
Ranch Hand
Posts: 271
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm:

Did you know if for Ubuntu is idem?

 
Norm Radder
Rancher
Posts: 1772
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't know anything about Ubuntu.
 
Dave Tolls
Ranch Hand
Posts: 2560
27
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general (and frankly all cases I've seen) it is not a good idea to set the CLASSPATH globally like that (ie in the environment variables in Windows).
Each project, or app, is likely to have its own classpath, and so a general one is next to useless, and also causes issues like this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!