Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NoClassDefFoundError (wrong name)

10 views
Skip to first unread message

Karsten Wutzke

unread,
Nov 21, 2001, 3:07:19 PM11/21/01
to
Hi all!

I don't get the following (on Win2k with a Cygwin bash shell):

I'm in a directory called:

"/work/Application"

From there, the directory structure is "com/domain/application". In this
directory lies a SINGLE class file which is called "Application.class",
furthermore this dir contains subdirectories (packages) called "gen",
"gui", "plugins" etc.

So the full path to the application class file is
"/work/Application/com/domain/application/Application.class... which has
the main method.

My CLASSPATH environment variable in the (Cygwin) bash shell is NOT set
at all.


1. When I type in "java Application", I get the following error dump:

Exception in thread "main" java.lang.NoClassDefFoundError: Application

Well, I admit that one. The VM can't find a class called "Application"
in the current directory or the classpath, so it fails.


2. So I'll simply add a classpath... When I type in "java -classpath
com/domain/application Application", I get the following error dump:

Exception in thread "main" java.lang.NoClassDefFoundError: Application
(wrong name: com/domain/application/Application)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Hmm... I set the classpath to the directory where "Application.class"
actually is and the VM seems to have found the file, but there seems to
be some conflict with the class name... What exactly is the VM complaing
about?


3. When I type in "java com.domain.application.Application", I get the
application to run as "expected"...


4. When I type in "java -classpath com/domain/application Application",
I get exactly the same error dump as with '2.', so again the VM seems to
have no problem finding the class file, but it does have a problem with
some naming internals (of class files?).

What is it I'm missing? Can anyone explain to me what the VM is
complaining about in 2. and 4. and WHY it fails? I'm also interested in
knowing why something was done in the VM that way...

Thanks in advance!

Karsten

Joona I Palaste

unread,
Nov 21, 2001, 4:56:14 PM11/21/01
to
Karsten Wutzke <karsten...@starconcept.com> scribbled the following:
> Hi all!

> "/work/Application"

What you are missing is your application's classname. Since it is in a
package other than the default package, you simply can't run it from the
default package.
Your way 3 above is the right way. Your application's name is
com.domain.application.Application, not Application. Your classpath
should point at the root of the package hierarchy (i.e. in the
directory that contains your com directory) and you should run the
application as in way 3.
From the package com.domain.application, you can refer to
com.domain.application.Application simply as Application. But when you
are starting a VM from the command line, you are not in any package,
so you must explicitly qualify all classnames.
As to why the VM has been designed this way, I don't know. I'm not a
Java expert...=)

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Keep shooting, sooner or later you're bound to hit something."
- Misfire

Jon Skeet

unread,
Nov 21, 2001, 5:51:40 PM11/21/01
to
Karsten Wutzke <karsten...@starconcept.com> wrote:

> I don't get the following (on Win2k with a Cygwin bash shell):

<snip>

See http://www.pobox.com/~skeet/java/compiling.html for hints and tips
on how to get the compiler and Java runtime to "like" your packages.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

0 new messages