Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > .class in OS X PB

.class in OS X PB
Thread Tools
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jan 27, 2001, 11:26 PM
 
Can anyone help me with this problem...

I have several .class java files on my computer. I really need to be able to use these files, and when I try to use it via the command line, it gives me an exception:

Exception in thread "main" java.lang.NoClassDefFoundError

I tried to specify the classpath using the -classpath, the same exception was thrown. The jdk does work however. I use ProjectBuilder to create source files, and it compiles them and runs them perfectly. I've even tried to add some of these .class files to projects, no luck.

Does anyone have any ideas or suggestions? Please give me any possible help... Thanks
     
Fresh-Faced Recruit
Join Date: Jan 2001
Location: San Jose, CA USA
Status: Offline
Reply With Quote
Jan 30, 2001, 06:32 PM
 
This is a classic Java FAQ. The .class files have to be in a directory hierarchy that matches the package hierarchy, and the _root_ of that directory hierarchy has to be added to the classpath. For example, if your class is com.foobar.MyClass the directory hierarchy might look like this:

~
javastuff
com
foobar
MyClass.java

Then you would enter
java -classpath ~/javastuff com.foobar.MyClass

I think Sun's Java Tutorial book has more info, as would nearly any beginner's book on Java.
     
Dedicated MacNNer
Join Date: Aug 1999
Status: Offline
Reply With Quote
Jan 31, 2001, 12:18 AM
 
Also, use this command:

java classname

NOT

java classname.class
     
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 6, 2001, 12:54 AM
 
Setting the classpath can be achieved by means of unix scripts. Here is an example.


GOAL:
To create an alias that helps out with the classpath issues. In this example I assume you are building "hello.java" that needs to import from "whatever.jar".

STEP 1:
create an empty directory at a convenient place (I prefer this to messing around with the JavaVM defaults).

[localhost:~] root# cd /System
[localhost:/System] root# mkdir java_classes

STEP 2:
Open the Terminal app. and edit your .cshrc file (save a copy before you do this)


[localhost:/System] root# cd
[localhost:~] root# cp .cshrc .cshrc_backup
[localhost:~] root# vi .cshrc

You can subsitute "vi" for your favorite editor. If you are using TextEdit, then make sure you set your preferences to "plain text". if you don't have a .cshrc file the you need to create one.


STEP 3:
Append the following to end of .cshrc

set jclasses="/System/java_classes/whatever.jar:."
alias jc 'javac -classpath $jclasses $1'

STEP 4:
save the file and load it.
[localhost:~] source .cshrc


STEP 5:
Make sure the whatever.jar file lives in the /System/java_classes directory

STEP 6:
Navigate to to directory where hello.java lives and type

[localhost:~] jc hello.java

STEP 7:
Pat yourself on the back! From now on you just need to edit the
jclasses parameter in your .cshrc

Here is what mine looks like:


set jclasses="/System/java_classes/jaxp.jar:/System/java_classes/jndi.jar:/System/java_classes/parser.jar:/System/java_classes/ejb.jar:/System/java_classes/jaxp.jar:/System/java_classe s/jndi.jar:/System/java_classes/parser.jar:/System/java_classes/servlet.jar:."


alias jc 'javac -classpath $jclasses $1'


HOMEWORK:

Create a script that automatically detects new .jar files in a directory and then updates your classpath.


Enjoy!

-Francisco J. Bido


iMac 17" G4 800MHZ & 768 SDRAM
     
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Feb 6, 2001, 12:58 AM
 
Setting the classpath can be achieved by means of unix scripts. Here is an example.


GOAL:
To create an alias that helps out with the classpath issues. In this example I assume you are building "hello.java" that needs to import from "whatever.jar".

STEP 1:
create an empty directory at a convenient place (I prefer this to messing around with the JavaVM defaults).

[localhost:~] root# cd /System
[localhost:/System] root# mkdir java_classes

STEP 2:
Open the Terminal app. and edit your .cshrc file (save a copy before you do this)


[localhost:/System] root# cd
[localhost:~] root# cp .cshrc .cshrc_backup
[localhost:~] root# vi .cshrc

You can subsitute "vi" for your favorite editor. If you are using TextEdit, then make sure you set your preferences to "plain text". if you don't have a .cshrc file the you need to create one.


STEP 3:
Append the following to end of .cshrc

set jclasses="/System/java_classes/whatever.jar:."
alias jc 'javac -classpath $jclasses $1'

STEP 4:
save the file and load it.
[localhost:~] source .cshrc


STEP 5:
Make sure the whatever.jar file lives in the /System/java_classes directory

STEP 6:
Navigate to to directory where hello.java lives and type

[localhost:~] jc hello.java

STEP 7:
Pat yourself on the back! From now on you just need to edit the
jclasses parameter in your .cshrc

Here is what mine looks like:


set jclasses="/System/java_classes/jaxp.jar:/System/java_classes/jndi.jar:/System/java_classes/parser.jar:/System/java_classes/ejb.jar:/System/java_classes/jaxp.jar:/System/java_classe s/jndi.jar:/System/java_classes/parser.jar:/System/java_classes/servlet.jar:."


alias jc 'javac -classpath $jclasses $1'


HOMEWORK:

Create a script that automatically detects new .jar files in a directory and then updates your classpath.


Enjoy!

-Francisco J. Bido


iMac 17" G4 800MHZ & 768 SDRAM
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2