Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

MAC/OS commands for javac, java

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/
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.

author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might simply try

cd /Users/jc/Desktop
java BeatBox

The use of CLASSPATH is to be avoided in general!
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:


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


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


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


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


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.


Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic