This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Mac/Windows difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Mac/Windows difference" Watch "Mac/Windows difference" New topic

Mac/Windows difference

Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
I wrote up a sample program for my students (it's a JFrame, with SwingUtilities.invokeLater and an anonymous inner class, none of which I think is actually relevant to this question).

It compiles and runs under BlueJ, on both Mac and Windows. It compiles and runs from the command line on the Mac. It compiles from the command line on Windows, but when I try to run it, I get a NoClassDefFound exception on the main class.

Are there common reasons that this kind of thing would happen? (For example, spaces in a directory name on Windows?)

SCJP 1.4
Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
OK, this is much more basic than I thought. I thought the difficulty might have something to do with the constructor, the anonymous inner class, maybe the cases in the class name... so I reduced the program to

and I'm still having the problem: it compiles and runs fine under BlueJ, it compiles and runs fine on the Mac command line, it compiles but doesn't run on the Windows command line.

I hate Windows....I hate Windows....I hate Windows....I hate Windows....
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11861

do you have a classpath environment variable set?

try running this from the directory where your .class files are

java -cp . <YourClassName>

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
Bingo! I told you it was really basic....
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Why not export your sample program as a JAR so that you don't have to fiddle with the environment variables on all your students' machines?

There is no emoticon for what I am feeling!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14961

Originally posted by Stephen Bloch:
I hate Windows....I hate Windows....I hate Windows....I hate Windows....

This error has nothing to do with Windows, and if you would have set the environment variable CLASSPATH on the Mac, you would have gotten exactly the same error on the Mac... Java = Java, doesn't matter on which operating system you run it.
[ June 19, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Have you checked out Aspose?
subject: Mac/Windows difference
jQuery in Action, 3rd edition