Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MAC/OS commands for javac, java  RSS feed

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdi there, rancher colleagues!

I wanted to try new things, & one of those things is seein' how does swing components look in a MAC/OS environment.

But I have encountered some problems because I don't quite know how to set the classpath.

I'm using the terminal, and I was able actually to compile some classes by using javac and attaching to it the directory where the .java file is. something like:

javac /Users/jc/Desktop/BeatBox.java
and well, as a result I got the .class file(s)

But when I tried this:

java /Users/jc/Desktop/BeatBox

It doesn't work, and I get the classic error: Exception in thread "main" java.lang.NoClassDefFoundError: BeatBox

How can I execute a Java Program in a Mac/os environment?(use java)

What is the command to see the current CLASSPATH in Mac/Os?

I hope someone could answer these questions. I really want to get started in MAC.

Sincerely,
Jose
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might simply try

cd /Users/jc/Desktop
javac BeatBox.java
java BeatBox

The use of CLASSPATH is to be avoided in general!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternately you could use

>java -cp /Users/jc/Desktop BeatBox

Like EFH I don't recommend using the environment variable CLASSPATH very much - people set it and forget why they put various things in there and keep adding new paths onto it, and it becomes a mess. Or they try to clean it up, and then some programs start failing unexpectedly because it turns out that part of the class path really was important for some programs. Instead I prefer to use -cp to tell each individual program what classpath it needs, without trying to force all programs to share.

However, if you must use the CLASSPATH environment variable:

>echo $CLASSPATH

will tell you what it's currently set to, and

>CLASSPATH=/foo/bar/baz

will set it to /foo/bar/baz. Often you'll want to do something like

>CLASSPATH=/eenie/meenie:$CLASSPATH

to add something at the beginning of the path (with : as a separator), or

>CLASSPATH=$CLASSPATH:/mienie/moe

to add something at the end. Eecuting the last three commands one after another will give you a CLASSPATH of

/eenie/meenie:/foo/bar/baz:/mienie/moe

And it's by doing stuff like this that people grow their classpaths into huger overly-complex things, which I prefer to avoid.
[ October 24, 2007: Message edited by: Jim Yingst ]
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning! Good afternoon and in case I miss it, Good night!

Thank you for the replies. I'll have to try those commands later, because unfortunately my MAC is now getting repaired.

I have confidence those commands are what I'm looking for.
For all the time invested I give you thanks.

Sincerely,

Jose
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!