File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Trying to complie Moose Greetings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to complie Moose Greetings" Watch "Trying to complie Moose Greetings" New topic
Author

Trying to complie Moose Greetings

Benjamin Thvedt
Ranch Hand

Joined: Jul 29, 2011
Posts: 31
I am having trouble trying to run the Moose Grettings program that can be found in the Create Your First Java program. I am using windows XP. I followed the instructions, I think I installed the SDK and set the path correctly, and when I type java -version in the command line window it shows java version 1.6.0_23. So I copied and pasted the code from the website into notepad, the file is named MooseGreetings.java and the code is here:



The file path is C:\JavaSrc\MooseGreetings.java. Anyway, I try to complie it as instructed by typing C:\JavaSrc> javac MooseGreetings.java and I get the message "'javac' is not recoginsed as an internal or external operable program or batch file". I then try to do it a different way by typing "java" instead of "javac" like this: C:\JavaSrc>java MooseGreetings.java and I get the message "Exeption in thread "main" java.lang.NoClassDefFoundError: MooseGreetings/java Caused by: java.lang.ClassNotFoundExcetpion: MooseGreeting.java at java.net.URLClassLoader$1.run<unknown Source> at .. " and it goes on. Does anyone know what I am doing wrong? This seems like it should be pretty simple..
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
did you install the JDK or JRE? Go to c:/program files/java and check if there is a JDK folder if so you need to add the following to your PATH variable: c:/program files/java/jdk1.6.0_23/bin
Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
please check if you have javac executable in your {javahome}/bin directory. Also make sure that you are pointing to {javahome}/bin directory in PATH variable. If you have jre installed on your machine instead of JDK, it wont compile your file. It will only help you execute your complied class file.


Regards,
Mahesh Kedari - Fidus Technologies Ltd.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
There are two basic kinds of java installation for your machine; the kind that allows you to run java programs, and the kind that allow you to compile AND run java programs. The former kind of installation would give you a 'java' command, but not a 'javac' command.

So you need to install a java development environment (JDE) instead of a java runtime environment (JRE).

'javac' is the right command to compile your source code (in your .java file); that creates a file with the same filename but a .class extension.

'java' is the right command to run your java file.

For historical reasons (I guess), your command should include the file extension on the compile step, but not not on the run step:

javac MooseGreetings.java
java MooseGreetings
Benjamin Thvedt
Ranch Hand

Joined: Jul 29, 2011
Posts: 31
Thanks for the replies and for clearing up the difference between java and javac. The program works, and I think the actual cause of the problem was that I didn't restart the command window after setting the path to the jdk bin in the control panel. That's my best guess anyway, I'm not 100 percent sure, but it works now. Oh, and thanks for clearing up the difference between the jde and jre.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
Benjamin Thvedt wrote:Thanks for the replies and for clearing up the difference between java and javac. The program works, and I think the actual cause of the problem was that I didn't restart the command window after setting the path to the jdk bin in the control panel. That's my best guess anyway, I'm not 100 percent sure, but it works now. Oh, and thanks for clearing up the difference between the jde and jre.


Your guess is correct; a setting made in Control Panel doesn't have any effect on the environment variables in windows that are already open.

Glad you got it working.

rc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to complie Moose Greetings