 |
 |
.class in OS X PB
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Status:
Offline
|
|
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
|
|
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
|
|
Also, use this command:
java classname
NOT
java classname.class
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |