• 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

Java Problem running on Teminal in Mac OS X Leopard

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to run java program on Terminal in MacOS. However the program compiles fine but gives Exception in thread "main" error on running java

I even tried java -cp ./Filename but it still didn't work

Also I could locate where the java 1.5 is installed. It's not in Applications/Java folder.

Please help me out in running the program.

I tried echo $CLASSPATH also but nothing comes on screen..

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the error you're getting?

You can find out where the executables are through "which javac", "which java" etc. although I'm not sure how that would help here. The rest of the JDK is someplace else, e.g. /Library/Java/Extensions is the extension library directory.
 
Avinash Tiwari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error is a Classpath error. Looks like it is not able to find the java to run the program I have created.

I tried to point the classpath to current directory to run it but still looks like some issue.

How do I point my classpath for running this program to current directory w/o changing the classpath permanently.

I am not able to echo my classpath.Is there any other command to know claspath variable value on MAC OS.

Please let me know.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, let's try something simple. Copy the following code - the entire lot - and just paste it into your Terminal

If you click on the "view plain" button you will be able to easily select, copy and paste everything.

What happened? Did you get the word "Hello" printed, or did you get a stack trace?

If you saw the word "Hello" printed, can you see what the difference is between how you are running your code and how I ran that example?

If you saw a stack trace, can you please copy the entire stack trace and paste it into this topic so we can better advise you?

Likewise, if my sample code worked, and you can't see what the difference is between what I did and what you are doing, can you please post your entire stack trace so we can advise you.



You shouldn't need to know where Java is installed - since you are getting an Exception, Java must be installed and must be running. But for completeness, this is how I find it on my computer:
Of course that tells me next to nothing, just that I am using whatever the default "current" version is. To see that, I would have to look at the version information:So right now, if I am working in a Terminal, I will be using JDK 1.5

Not sure why I would want to go to all that trouble though, since I can get the same information by typing java -version at the command line. Much simpler. I never need to look at what Apple have actually installed or where. Most of the time I work in Eclipse which I have set to default to JDK 6, which it found for me automagically.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tell us some details. Think how much easier it would be to help you if you told us which Exception you are suffering.
 
Avinash Tiwari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried your way and it worked.

Still not sure what's the difference.

When I run through a file on system rather than using cat it fails with same error...wrong name....

so what are your thoughts...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without knowing anything about your app/directory structure, library dependencies, etc. it's going to be very difficult to give you the command line necessary to run your program. If your code has no external dependencies then the -cp argument should get the name of the directory where your compiled output is.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I previously wrote:Tell us some details. Think how much easier it would be to help you if you told us which Exception you are suffering.

You see, people can't help because they haven't got enough details.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic