• 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

Trying to complie Moose Greetings

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic