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 Mac/Windows difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Mac/Windows difference" Watch "Mac/Windows difference" New topic
Author

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
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

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: 14430
    
  23

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mac/Windows difference