Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Problem running on Teminal in Mac OS X Leopard

 
Avinash Tiwari
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • 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..

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic