• Post Reply Bookmark Topic Watch Topic
  • New Topic

HelloWorld, close but not quite there  RSS feed

 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Windows Vista.

Cmd javac resides here: c:\program files (x86)\java\jdk1.6.0_16\bin

My java source for HelloWorldApp resides here: c:\JavaSource

With directory set to bin, it cannot find the source and with dir at source cannot find javac. I believe the -sourcepath option will do the trick. With the directory set to ...\bin I tried java HelloWorldApp.java -sourcepath c:\Javasource\HelloWorldApp.java but it's not working, I get file not found message.

I'm a total newbie, any help appreciated!

Russ Sprague
Kensington, MD
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Russ Sprague wrote:With directory set to bin, it cannot find the source and with dir at source cannot find javac. I believe the -sourcepath option will do the trick. With the directory set to ...\bin I tried java HelloWorldApp.java -sourcepath c:\Javasource\HelloWorldApp.java but it's not working, I get file not found message.


Your best bet is to probably set your current working directory to be at source, and set your PATH environment variable to include the bin directory.

Henry
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome to JavaRanch

avi sinha
 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply. I guess I'm still doing something incorrectly.

From the command line, I did 'cd c:\JavaSource' to chgdir to where the source is.

Next I did set path = c:\program files (x86)\java\jdk1.6.0_16\bin since javac resides in bin

Next 'javac HelloWorldApp.java' but got response 'javac is not recognized as an internal or external command...'
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like most things, there is something about it in the Java™ Tutorials. That very error is discussed in that section. It leads indirectly to the installation instructions, and I think it is §4.
Is (x86) actually part of the name of the folder? You may need quote marks round the path if it contains a space (eg after program before files).
 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm all set now. Turns out it was a very ordinary typo that got me. My source file name was hellowworldapp rather than helloworldapp. Using c:\javasource as my initial dir then following up with set path=jdk.... did the trick. Thanks so much everyone who made replies. Once I learn more, I hope to contribute back. Is there something I should do to close this out as an active thread or just leave it as is?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to close a thread.simply leave it and it will sink into our history archives, in case anybody searches for the same problem.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Is (x86) actually part of the name of the folder? You may need quote marks round the path if it contains a space (eg after program before files).

If you're running a 64-bit version of Windows then the (x86) will probably be part of the name of the folder for 32-bit programs. You do indeed need to enclose the path in "quotation marks" if it contains spaces.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:. . . If you're running a 64-bit version of Windows then the (x86) will probably be part of the name of the folder for 32-bit programs. . . .
Thank you. I never knew that.
 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, (x86) was a proper part of the path. The final fix I needed to make was to correct a simple typo.
 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I was all set but have more questions.. Here is what worked for javac:

1) cd c:\javasource
2) set path = c:\program files (x86)\java\jdk1.6.0_16\bin
3) javac HelloWorldApp.java or javac MyFirstApp.java

My apps are compiled into c:\javasource

but now I want to run the app with cmd 'java'. When I try it, it says 'Could not find the main class..'

The java commdand is in bin. The compiled apps are in javasource. I can't seem to find the right setpath, setclass or whatever to make things come together.

Any assistance appreciated and I will be checking tutorials also!
 
Russ Sprague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, nevermind. I just closed the cmd window, started from scratch and the apps are working fine. I will switch over to NetBeans in time but thought I might get a better grasp of things with manual commands. I probably had some incorrect path set up and by closing the cmd window and restarting got that straightened up.

Russ
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't migrate to NetBeans until you are a lot more experienced. You have more than enough to learn without trying to learn NetBeans too.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!