• 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

MAC/OS commands for javac, java

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic