Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Zion Grail

macrumors regular
Original poster
Dec 24, 2002
104
0
Chicagoland
Ever since I got the Java update I can't seem to run any of my classwork Java programs. No matter what I do, I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError

Even in a simple HelloWorld! program I get this error. All of my programs, even ones that worked before, have started behaving like this.

Anyone else have this kind of problem?

*EDIT*

Even the ready-to-compile java files I got form the book's CD are acting like this!!
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
How exactly are you trying to run these? Inside an IDE, from command line?

remember to compile your .java file first using javac and then run it with the java command (no extension on the file to be run)

For example
PHP:
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("I love my mac.");
  }
}

from terminal:

javac HelloWorld.java

this creates HelloWorld.class, and then

java HelloWorld

If this is completely obvious, I apologize, but every once and a while I brainfart and run the .java file through the java command and whoopsy...same problem

Good Luck
 

TEG

macrumors 604
Jan 21, 2002
6,625
173
Langley, Washington
That is how he got the problem, the update caused It. I've been having a similar problem when compiling. However, no problems with exitsting java apps. I'm just hoping Apple can get Java 5.0 (1.5) out quickly.

TEG
 

Zion Grail

macrumors regular
Original poster
Dec 24, 2002
104
0
Chicagoland
Fixed it, somewhat

I can't be sure if it's the update or what, but I've found the problem - my classpath is blank. Nothin' in there. Gone.

I had to find where Java keeps it's classes on my system and manually set it, and I have to tell my system to inclde whatever current directory I've put my projects in my going to the command line, going to the directory i'm using, and typing

export CLASSPATH=$CLASSPATH:.

Then, to run anything in that directly, I *STILL* need to use the command

java -cp $CLASSPATH:. InsertClassNameHere

Then it works.

This is damn annoying, Apple. How did such a huge mistake get by you?
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
Zion Grail said:
I can't be sure if it's the update or what, but I've found the problem - my classpath is blank. Nothin' in there. Gone.

I had to find where Java keeps it's classes on my system and manually set it, and I have to tell my system to inclde whatever current directory I've put my projects in my going to the command line, going to the directory i'm using, and typing

export CLASSPATH=$CLASSPATH:.

Then, to run anything in that directly, I *STILL* need to use the command

java -cp $CLASSPATH:. InsertClassNameHere

Then it works.

This is damn annoying, Apple. How did such a huge mistake get by you?

You need to set your CLASSPATH. Its not Apples responsibility. If you want it to be more permanant, look into editing the appropriate .rc file associated with your shell. If you are using bash then modify the .bashrc in your home directory. If you are using tcsh then you will modify your .tcshrc file. Add that export command to either file and it will automatically get set when you log in.

Edit: I think you have to use the setenv command instead of export. So your command should look like

setenv CLASSPATH .:$CLASSPATH
 

bousozoku

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
TEG said:
That is how he got the problem, the update caused It. I've been having a similar problem when compiling. However, no problems with exitsting java apps. I'm just hoping Apple can get Java 5.0 (1.5) out quickly.

TEG

It's not surprising. There was also an issue when they revised to 1.4 and they eventually got a developer tools update together which took care of the problem. If you look at downloads for tools on the Apple developer site, you'll find the update in 2003.

Hopefully, they'll be swift about it.
 

Zion Grail

macrumors regular
Original poster
Dec 24, 2002
104
0
Chicagoland
kingjr3 said:
You need to set your CLASSPATH. Its not Apples responsibility. If you want it to be more permanant, look into editing the appropriate .rc file associated with your shell. If you are using bash then modify the .bashrc in your home directory. If you are using tcsh then you will modify your .tcshrc file. Add that export command to either file and it will automatically get set when you log in.

Edit: I think you have to use the setenv command instead of export. So your command should look like

setenv CLASSPATH .:$CLASSPATH

When I was running 10.2, it was already set and all I needed was the "java" and "javac" commands. If they did it before, I'd expect Panther to have it set up as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.