This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes SOS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SOS" Watch "SOS" New topic


V Bose
Ranch Hand

Joined: Jul 10, 2003
Posts: 113
My directory structure is

The file has a package statement
package src;
From the directory Cluster (@ the DOS prompt) when I try
java -cp build\src Normalize
it throws

Exception in thread "main" java.lang.NoClassDefFoundError: Normalize (wrong name: src/Normalize)

How do I get this class to run ?
[ February 18, 2004: Message edited by: V Bose ]
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Your problem is you're going in to the package. Do this instead:
java -cp build src.Normalize

Joined: May 06, 2002
Posts: 3
Since you wrote "package src;" at the top of your class, you will have to run the class by referring to it as "src.Normalize".
So to run the class from the Cluster directory, try:
java -cp build src.Normalize
So you're pointing java to the directory above the beginning of your package hierarchy (you only have one level in your package "src") and then refer to the class using the package name "dot" class name. So if you had more levels in your package like "package com.pizzahut.util;" then you will refer to your class as "com.pizzahut.util.Normalize" in order to run it.
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
In this case the class name is src.Normalize and the class files are stored under the "build" folder, so java -cp build src.Normalize should get it running.
However, calling your package "src" is not perhaps the most descriptive name you could come up with. In fact it is misleading and could cause confusion with the real source directory "Cluster/src".
The convention is to use your domain name (in reverse order) followed by a descriptive name for the package. For example, if you owned the domain name "" you might like to place your class in the package "com.vbose.cluster".
Talking of names, the name of the class "Normalize" appears to describe an action (method) rather than an object / class?
I agree. Here's the link:
subject: SOS