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 Java Problem running on Teminal in Mac OS X Leopard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Problem running on Teminal in Mac OS X Leopard" Watch "Java Problem running on Teminal in Mac OS X Leopard" New topic
Author

Java Problem running on Teminal in Mac OS X Leopard

Avinash Tiwari
Ranch Hand

Joined: Sep 20, 2006
Posts: 50
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..


Work hard and rest not till the job is done....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Avinash Tiwari
Ranch Hand

Joined: Sep 20, 2006
Posts: 50
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

Joined: Mar 28, 2003
Posts: 11280
    
  59

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.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
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

Joined: Sep 20, 2006
Posts: 50
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 13, 2005
Posts: 36520
    
  16
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
 
subject: Java Problem running on Teminal in Mac OS X Leopard
 
Similar Threads
automatically compiling a java program
Help with Runtime.exec()
Mahalo(TransactionManager) Service in Jini
Sockets under Windows XP OS
Accessing enclosing class' super class in inner