Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Using the Command Line

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm not sure what is not working here.  I know I have done this before.  I keep getting "file not found "error when I go to run my program from the command line prompt.  Any suggestions or guidance would be appreciated.  I have included a screenshot as an attachment.  

Thanks in advance
filenotfound.png
[Thumbnail for filenotfound.png]
 
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is preferred that you cut and paste command console text into your post rather than supplying a  screen snap shot.

What is the directory path of where your .java file is located? I have no way to know if you were in the correct directory when you ran javac.
 
Marshal
Posts: 68899
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Also please tell us what happens when you pass echo %CLASSPATH% to the command line. Older books tell you how to set a system CLASSPATH, but that usually causes a lot of trouble.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the command prompt:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\hanna>cd Documents

C:\Users\hanna\Documents>cd New Folder (3)


C:\Users\hanna\Documents\New Folder (3)>javac HowtheMainMethodWorksPractice.java

javac: file not found: HowtheMainMethodWorksPractice.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\Users\hanna\Documents\New Folder (3)>



Here is the path from Netbeans:
C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice

Here is what I get when I pass echo %CLASSPATH%

C:\Users\hanna\Documents\New Folder (3)>echo %CLASSPATH%
C:\Program Files\Java\jdk1.8.0_161\lib\*.jar

C:\Users\hanna\Documents\New Folder (3)>

 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are in
C:\Users\hanna\Documents\New Folder (3)

Then enter
dir /S

What does it give you?

Also, what does
javac -version

give you?
 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Rancher
Posts: 3714
34
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is the path from Netbeans:
C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice


Is that the path to a folder
or to the HowtheMainMethodWorksPractice.java file?

What folder is the HowtheMainMethodWorksPractice.java file in?
 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Try
C:\Users\hanna\Documents\New Folder (3)> javac src\*


That might not have been a good idea in your case.

In your project directory do you have a sub-directory named 'bin' or 'target'? This is usually where the .class files go. The command I gave you above would have put the .class files in the 'src' directory which is incorrect. Instead you would need to run:

javac src\*.java -d bin
 
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the project folder is C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice the src, bin and/or target folders are probably in there.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,I gave that a try.  Here is what happened:

C:\Users\hanna\Documents\New Folder (3)>javac src\*.java -d bin
javac: file not found: src\*.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\Users\hanna\Documents\New Folder (3)>
 
Norm Radder
Rancher
Posts: 3714
34
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What folder is the HowtheMainMethodWorksPractice.java file in?
That is where the javac command should be issued.
 
Knute Snortum
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try cd-ing into C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice and typing dir /S.  What do you see?
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I tried that and it ran through all the projects in the directory and finally spit out this at the end:

    Total Files Listed:
           4501 File(s)    705,490,759 bytes
          12413 Dir(s)  55,711,854,592 bytes free
 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, we're not getting any where. What PROJECT is HowtheMainMethodWorksPractice.java in? What directory in that project is it in?

You need to be cd'ing to the PROJECT folder.
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What folder is the HowtheMainMethodWorksPractice.java file in?
That is where the javac command should be issued.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I navigate to the .java file the directory looks like this:

C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthemainmethodworkspractice

Once there, I see the file:

HowtheMainMethodWorksPractice.java
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to navigate there using the command prompt this is what I get:

C:\Users\hanna\Documents\New Folder (3)\src>cd howthemainmethodworkspractice
The system cannot find the path specified.
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like there are multiple paths:


C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthemainmethodworkspractice


That shows the src folder in the HowtheMainMethodWorksPractice folder, not the New Folder (3) folder.


C:\Users\hanna\Documents\New Folder (3)\src>cd howthemainmethodworkspractice


What folders are in the New Folder (3) folder?
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I think I am following along.  I really appreciate you troubleshooting this with me on a weekend.  Here is my last attempt at running it from command prompt:


C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthe
mainmethodworkspractice>javac HowtheMainMethodWorksPractice.java

C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthe
mainmethodworkspractice>java HowtheMainMethodWorksPractice
Error: Could not find or load main class HowtheMainMethodWorksPractice
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a HowtheMainMethodWorksPractice.class file in the folder where the java command was issued?
Is the HowtheMainMethodWorksPractice class in a package?
If it is in a package, then the location where the java command is issued needs to be changed
and the full name of the class including the package needs to be added:  java thePackage.TheClassName
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I am seeing.  I know that it is preferred not to include screenshots but I dont want to take up too much of your time
classPath.png
[Thumbnail for classPath.png]
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a package statement in the java source file?
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it is:

package howthemainmethodworkspractice;
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The package name is part of the full class name.  It needs to be included in the java command:  
java howthemainmethodworkspractice.<TheClassNameHere>

The java command should be issued in the directory that contains the howthemainmethodworkspractice folder.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I gave that a try too.  Here is what happened:


C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthe
mainmethodworkspractice>java howthemainmethodworkspractice.HowtheMainMethodWorks
Practice
Error: Could not find or load main class howthemainmethodworkspractice.HowtheMai
nMethodWorksPractice
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You missed this:


The java command should be issued in the directory that contains the howthemainmethodworkspractice folder.



The last post shows the java command was issued in the howthemainmethodworkspractice folder, NOT in the folder that contains the howthemainmethodworkspractice folder - src


C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthemainmethodworkspractice>java howthemainmethodworkspractice.HowtheMainMethodWorksPractice

 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I am still having trouble.  But I do appreciate you trying to help. Thank you.
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am still having trouble.


Can you explain?
 Copy any output that shows the problem and paste it here.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was my last attempt.  There is something simple I am missing because I used to do this quite easily.

C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src>java h
owthemainmethodworkspractice.HowtheMainMethodWorksPractice
Error: Could not find or load main class howthemainmethodworkspractice.HowtheMai
nMethodWorksPractice
 
Campbell Ritchie
Marshal
Posts: 68899
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try finding out what is in that directory. And shorten the package and class names, so they will fit on a line, and so they are different. Your error messages are awkward to read at present.
You might not find the XYZ.class file in a src directory because it might only contain the source files (XYZ.java).
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what you have told us, your last attempt should have worked.
Have you changed  or renamed or deleted anything?
 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've been asked a few times to give us a directory tree and you haven't. It's difficult to help you if you won't help us. This will tell you what files you have and how they are organized.

cd C:\Users\hanna\Documents\New Folder (3)
dir /S HowtheMainMethodWorksPractice
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\hanna>cd Documents

C:\Users\hanna\Documents>cdNew Folder (3)
'cdNew' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\hanna\Documents>cd New Folder (3)

C:\Users\hanna\Documents\New Folder (3)>dir /S HowtheMainMethodWorksPractice
Volume in drive C has no label.
Volume Serial Number is BC9A-F1A6

Directory of C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice

02/05/2020  04:05 PM    <DIR>          .
02/05/2020  04:05 PM    <DIR>          ..
02/05/2020  04:05 PM             3,672 build.xml
02/05/2020  04:05 PM                85 manifest.mf
02/05/2020  04:05 PM    <DIR>          nbproject
02/05/2020  04:05 PM    <DIR>          src
              2 File(s)          3,757 bytes

Directory of C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\nbproject

02/05/2020  04:05 PM    <DIR>          .
02/05/2020  04:05 PM    <DIR>          ..
02/05/2020  04:05 PM            79,980 build-impl.xml
02/05/2020  04:05 PM               475 genfiles.properties
03/05/2020  08:33 AM    <DIR>          private
03/05/2020  08:33 AM             2,577 project.properties
02/05/2020  04:04 PM               537 project.xml
              4 File(s)         83,569 bytes

Directory of C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\nbproject\private

03/05/2020  08:33 AM    <DIR>          .
03/05/2020  08:33 AM    <DIR>          ..
03/05/2020  08:33 AM                 0 config.properties
03/05/2020  08:33 AM               182 private.properties
              2 File(s)            182 bytes

Directory of C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src

02/05/2020  04:05 PM    <DIR>          .
02/05/2020  04:05 PM    <DIR>          ..
03/05/2020  11:22 AM    <DIR>          howthemainmethodworkspractice
              0 File(s)              0 bytes

Directory of C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src\howthemainmethodworkspractice

03/05/2020  11:22 AM    <DIR>          .
03/05/2020  11:22 AM    <DIR>          ..
03/05/2020  11:22 AM               517 HowtheMainMethodWorksPractice.class
02/05/2020  04:09 PM               507 HowtheMainMethodWorksPractice.java
              2 File(s)          1,024 bytes

    Total Files Listed:
             10 File(s)         88,532 bytes
             14 Dir(s)  56,125,280,256 bytes free

C:\Users\hanna\Documents\New Folder (3)>
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the source file: HowtheMainMethodWorksPractice.java
Be sure to wrap in code tags.  Select the code and press the Code button.
 
Andrew Hann
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code works for me:


D:\JavaDevelopment\Testing\ForumQuestions13>java howthemainmethodworkspractice.HowtheMainMethodWorksPractice
I hope everyone is safe and healthy

D:\JavaDevelopment\Testing\ForumQuestions13>

 
Knute Snortum
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Hann: You would need to cd into this folder:

   C:\Users\hanna\Documents\New Folder (3)\HowtheMainMethodWorksPractice\src

and then type your java command:

   java howthemainmethodworkspractice.HowtheMainMethodWorksPractice
 
Norm Radder
Rancher
Posts: 3714
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A moderator needs to edit some of the console contents that the OP posted and undo the wrap so we can easily see and search for text that was entered and reported on the console.
Staff note (Knute Snortum):

Done.

 
Carey Brown
Bartender
Posts: 7065
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do your building and running from your project directory instead of your src directory you can follow this template (which I tried and verified).


Source:

TO BUILD

cd \tmp\HelloProject
javac src\pkg\*.java


TO RUN

cd \tmp\HelloProject
java -cp src pkg.Hello
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic