1. Member
Join Date
Feb 2009
Posts
92
Rep Power
0

## class path problem?

I thought I understood the process of creating packages, but I have been unable to make this application work when I try to create an application using files in multiple directories:
This is my directory tree
L:\JAVAHW
|___rdt
|___Prompts/ (java files)
|___PayRoll/ (java files)

This is my imports and package definition in one of the applications in the
PayRoll directory

package rdt.PayRoll;
import rdt.Prompts.Prompts;
import java.util.Scanner;
import java.io.BufferedWriter;

the package statement for the one file in Prompts is
package rdt.Prompts

I can compile all files without error, as seems to be typical with this type of
problem.

I clear and set the class path with a .bat file (Vista OS)
set CLASSPATH=
set CLASSPATH=.;L:\javahw\;

This is the output I get when I try to run the app.

java.lang.NoClassDefFoundError: PayDay_App (wrong name: rdt/PayRoll/PayDay_App) (and more)

The program was developed in eclipse using two different packages, and it works when I put everything in the same directory. Putting a package statement in a HelloWorld app works correctly: java rdt.Payroll.Hello displays.

This seems so straight forward and I reviewed the sun tutorial. I am completly stuck.

2. I'm no pro at command line compiling and running, but perhaps your using javahw instead of JAVAHW is of issue. Myself, I generally don't set the OS's CLASSPATH property as you are doing, but instead use a java -cp option.

I recommend that you show us exactly how you are trying to run your program, what you type in (you don't use the .class extension here do you?) and then show us the exact error message(s) that you receive.

Much luck!
Last edited by Fubarable; 11-15-2009 at 06:05 AM.

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,611
Rep Power
12
Specify the complete class name when you run the app (PayDay_App could be class in any package whatsoever).

Java Code:
java rdt.PayRoll.PayDay_App
(often you would specify the classpath as part of the command you use to run the application, and would start package names with a lower case letter.)

4. Member
Join Date
Feb 2009
Posts
92
Rep Power
0
java.lang.NoClassDefFoundError: PayDay_App (wrong name: rdt/PayRoll/PayDay_App)
at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: PayDay_App. Program will exit.

is the error message.

The capitalization of JAVAHW was something I hadn't considered. When I looked at it, the capitalization was created by the dos tree command. It is actually in small case on the drive.

I have been using the full package name as was indicated in the portion of the error message. The rest of the message is just gobbledy-gook to me.

My understanding is that if the code is in c:\foo\bar\foobar.java and the package is bar,
then the class path should be c:\foo and the command line should be java bar.foobar.
I am running the program from the PayRoll director using java rdt.PayRoll.PayRoll_App, which is the name parroted in the error message.

I've also played around with using -cp and -classpath switches.

I'll try one more thing. I've assumed that all the code I need to run the app is in the application file, so that was the only path I put in the path statement. If the Prompt class is needed at runtime, it would need the class path to that file.

5. Member
Join Date
Feb 2009
Posts
92
Rep Power
0

## Problem solved

Ran the command line from javahw, not javahw\rdt\PayRoll, and it worked.
Solved

6. Member
Join Date
Jul 2007
Posts
74
Rep Power
0
I would advice all Java newbees to use IDE

7. Member
Join Date
Feb 2009
Posts
92
Rep Power
0
I agree. Many of the questions posted on forum could be solved using a debugger.

In this case, the files were part of a homework assignment that has to be handed in. I think that my partitioning was appropriate, and simply wished to pass the file structure to the instructor who can compile the files and run from his own directory. Using packages should allow him to do so. Perhaps a .jar would be better, but I haven't studied that process yet.

I am bothered that I have to change directory to the end of the classpath to make things run. With the CLASSPATH environment set, and the structure of the package, java should be able to run an application from any location.

FWIW, advice is a noun. "I would advise you to take this advice." I know I make my own share of typos, and occasionally use their or there when I know I mean they're.

8. Originally Posted by rdtindsm
I am bothered that I have to change directory to the end of the classpath to make things run. With the CLASSPATH environment set, and the structure of the package, java should be able to run an application from any location.
It can do this.

9. Moderator
Join Date
Apr 2009
Posts
12,264
Rep Power
20
Originally Posted by Swamipsn
I would advice all Java newbees to use IDE
I don't.

Understanding the classpaths, packages and how they map to the underlying directory structure is very important. I've seen too many questions from people who have only used IDEs regarding class not found exceptions, or runtime problems when deploying their app outside of an IDE...questions they would have known the answer to if they'd learned the basics first.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•