• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Java -cp problem cannot find main class

 
Greenhorn
Posts: 1
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys im new on this website and also newbie with java i got a problem using this command java -cp ".;C:\temp\someOtherLocation;c:\temp\myJar.jar" myPackage.MyClass)    ---> {"that's from java 8 certification book"}
the command that i use is : java -cp ".;C:\Users\wassim-rim\Desktop\Test2Java" packageb.Test2B.java
i want to specify the location of classA  on the file Test2Java  located on desktop so it can be reachable by class Test2B.java  but i don't know  to solve the problem(impossible to find or load the main class packageb.Test2B.java .

im waiting your response thank you in advance (sry for my bad english ) .
 
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

command that i use is : java -cp ".;C:\Users\wassim-rim\Desktop\Test2Java" packageb.Test2B.java  


That looks like a source file name (ends with .java) not the name of the class file.
If the class file is in the packageb folder and that folder is in the current folder where the java program is executed, the java program should find it.

Please copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.
 
Marshal
Posts: 80645
473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you have included the .java extension, then you have done something different from the instruction the book gave you. The example shows the classpath being set without an extension. You were right to add .; to that classpath. This part of the Java™ Tutorials might help.
Why are you keeping your Java® work on your desktop? All you will achieve is filling it with hundreds of old XYZ.java and XYZ.class files. I suggest you do this at the command line:-...or whatever other name you want for that folder. Next time you only need line 2.
 
Sheriff
Posts: 9012
655
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rim wassim wrote:hello guys im new on this website


A warm welcome to the Ranch

rim wassim wrote:that's from java 8 certification book


Please let us know, which book is that? Thank you.

Well, the idea of this exercise is, that you really need to go through the struggle in order to understand yourself how things work. However, the mistakes you introduced are fundamental and might be difficult to debug, because this exercise I don't think explains these parts where you were mistaken.

rim wassim wrote:i use is : java -cp ".;C:\Users\wassim-rim\Desktop\Test2Java" packageb.Test2B.java


1. When you specify classpath, you need to specify files with their extensions.
2. When you specify the class you want to execute (with java command), you don't specify file (class's) extension.
3. When you compile classes, you need to specify extensions of the files in the classpath(s) as well as for the classes you are about to compile.
reply
    Bookmark Topic Watch Topic
  • New Topic