• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java -cp command line it doesn't find the file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Together

As you see in the files attached, i had a problem with the java -cp command not finding the file, however i do not understand why exactly.
In the first attatchment picture you see the checker2 batch file, with the command "java -cp %MY_CLASSPATH% uebung12.as.aufgabe02.DirectedDFS_TestTask1c" it does not work and doesn't even find the file
DirectedDFS_TestTask1c despite it being in the same directory and it being defined in the class as "package uebung12.as.aufgabe02;"

In the second you see the command line, which as you see, gives out the fact that it couldn't find the file in the first place.

"Fehler: Hauptklasse uebung12.as.aufgabe02.DirectedDFS_TestTask1c konnte nicht gefunden oder geladen werden"
which means Error: Main class uebung12.as.aufgabe02.DirectedDFS_TestTask1c could not be found or loaded.

In the third picture you can see that it is in the same directory.

Does somebody know what the problem is? Thank you all for reading
1.PNG
[Thumbnail for 1.PNG]
2.PNG
[Thumbnail for 2.PNG]
3.PNG
[Thumbnail for 3.PNG]
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

It appears to me that you don't have any compiled classes to run, unless your compiled class is inside the "Woche 12\bin\uebung12\as\aufgabe02\" folder. Can you please show us what's in there?

A piece of advice that might not solve your situation, but might make your life easier in the future: Don't put anything in your source code packages that is not source code. Assuming that "Woche 12" is your project's root folder, you should put your build scripts and documentation there. Your build script then looks like this:

Notice that this build file will also become easier to read if you  use a name like "src" instead of "For the love of god".

Please, for future reference, don't use screenshots to share text files. It makes it hard for us to read and recreate your situation. Copy text inside your post, and enclose it in code tags like [code]this[/code]. An easy way to achieve this is to select your code and press the "Code" button. Use the "Preview" button to see what the code looks like before you submit your post.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did "Woche 12" come from, Stephan? While one of the OTHER reasons why we don't like screenshots is that they can't be searched for text, I can't seem to find that directory anywhere other than in your own posting.

Just for the record, it's a really bad idea to have embedded spaces in file and directory names for programming projects. If you forget to quote something, then the command-line parsers can get really confused. You won't have to risk that if your directory is named "UmGottesLiebe", instead (although you WILL have to remember to properly capitalize the letters!). Besides, how can you be properly German if you don't onelongword things?

Also, have I forgotten, or is it not true that instead of setting MY_CLASSPATH and using it with "-cp", a shorter way is to set CLASSPATH and the compiler and runtime will automatically use that?
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Where did "Woche 12" come from, Stephan?


Yeah, it's in the last screenshot, in the address bar of the filesystem explorer.

Also, have I forgotten, or is it not true that instead of setting MY_CLASSPATH and using it with "-cp", a shorter way is to set CLASSPATH and the compiler and runtime will automatically use that?


Yes, that will work. Personally I'm not a fan of this approach, because the class path that java needs is typically different from the class path that javac needs.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wilkommen in der Ranch, Kai!

A more typical Java project directory organization would look something like this:

C:\Users\Me\JavaProjects\Aufgabe1
      |
      + src
      |
      + classes


A project organized for a build tool such as Maven complicates that a little, but this layout is all you would need for a basic "getting started" type project
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic