On Thu, 7 Dec 2000, Jacob Nikom wrote:
> Hi,
>
> I found that I cannot do very simple thing in Java.
>
> If I start Java application like HelloWorldApp.java
> in the directory where HelloWorldApp.class file is
> it works OK.
>
> If I start it in another directory like
> java Another_directory/HelloWorldApp/HelloWorldApp
>
> it complains:
> Exception in thread "main" java.lang.NoClassDefFoundError:
>
> Is there any way to circumvent it without using a script?
The java command does not behave like any other unix command you've
seen. It does not take a unix or dos path to the class file directly.
Do it like this:
java -classpath ./Another_directory/HelloWorldApp HelloWorldApp
The classpath takes one or more : separated directory paths, where
each path is the top of a package structure. If your HelloWorld.java
file contains no package statement, then its classpath is just the
directory where the compiled class file lives.
If, however, your java file contained something like:
package com.foo
Then your class file would have to live in:
./Another_directory/HelloWorldApp/com/foo
And the above java command would have to be changed to include the
java package name on the class file parameter thusly:
java -classpath ./Another_directory/HelloWorldApp com.foo.HelloWorldApp
This takes some getting used to, but if you are careful to always make
your directory structure match your package namespace structure, and
remember to put the *top* of the directory structure in your classpath,
then just about everything related to java will work properly.
--
Joi Ellis Software Engineer
Aravox Technologies [EMAIL PROTECTED], [EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]