aspose file tools*
The moose likes Beginning Java and the fly likes Help with compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with compiling" Watch "Help with compiling" New topic
Author

Help with compiling

james thompson
Greenhorn

Joined: Feb 25, 2010
Posts: 3
I have read through all the steps here
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html

I am trying to compile the hello world program and I keep getting these errors as seen in my attachment. What am I doing wrong here?



[Thumbnail for helpplease.jpg]

Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

You have to add classpath.

execute the following command.

java -cp . HelloWorldApp


- Chinna
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Read the section Common Problems (and Their Solutions) in that same tutorial - it explains the exact error message you get and what to do about it.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
james thompson
Greenhorn

Joined: Feb 25, 2010
Posts: 3
Maneesh Godbole wrote:James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java


Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.

I dont understand the cp? Where am I pointing it to?

Edit ok after further reading thanks to your guys suggestions I got it... Now here
set CLASSPATH=
Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the section in the JDK 6 installation instructions. The CLASSPATH variable is set in the same manner.

So i need to set the CLASSPATH variable somewhere else to avoid this problem in the future?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

james thompson wrote:
Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.


Well your post title said help with compiling and you also said I am trying to compile the hello world program and I keep getting these errors
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

CLASSPATH is set a list of directories or jar files separated by ";" (in windows).

CLASSPATH is used by JAVA Virtual machine to find the classpaths.

When you run "java HelloWorldApp", here *java* program is the virtual machine and *HelloWorlApp* is your main class.
So it will try to search for HelloWorldApp in CLASSPATH path, if it is defined.

If CLASSPATH is not defined, current directory is by default assumed as the classpath.


Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Will suggest you, to go through the following link..

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
Welcome to the Ranch

Please use copy-and-paste to post the error messages, not screen capture. Click the top left icon on the command window, then edit, then mark, then highlight the text with the mouse, then enter to copy to clipboard. It is much easier to read.

When you compiled the file, with
javac HelloWorldApp.java
I presume you got no error messages? If the file compiles, nothing happens; you only get error messages if something goes wrong. Try the "dir" instruction to see where the .class file is.
If it is in your current directory, try the earlier suggestion of
java -cp . HelloWorldApp
Remember the java tool doesn't require extensions.

If that doesn't work, post the code you are compiling.

You should not normally set a system classpath, but some applications eg QuickTime, set a system classpath which can b*gg*r up your normal Java settings. If that is the case add .; to the beginning of the system classpath. You can have several .s in your classpath; I have tried it, and it doesn't seem to do any harm.
james thompson
Greenhorn

Joined: Feb 25, 2010
Posts: 3
thank you guys for all the help now I can finally start working through my head first java book
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
Got it working?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with compiling