Results 1 to 9 of 9
Thread: class path problem?
- 11-15-2009, 04:42 AM #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.
-
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 05:05 AM.
- 11-15-2009, 04:53 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Specify the complete class name when you run the app (PayDay_App could be class in any package whatsoever).
(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.)Java Code:java rdt.PayRoll.PayDay_App
- 11-15-2009, 06:55 AM #4
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
java.lang.NoClassDefFoundError: PayDay_App (wrong name: rdt/PayRoll/PayDay_App)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
Could not find the main class: PayDay_App. Program will exit.
Exception in thread "main"
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.
- 11-15-2009, 07:06 AM #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
- 11-16-2009, 07:16 AM #6
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
I would advice all Java newbees to use IDE
- 11-16-2009, 04:34 PM #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.
-
- 11-16-2009, 05:09 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
Similar Threads
-
how to set the class path
By lashu in forum New To JavaReplies: 1Last Post: 08-21-2009, 01:04 PM -
Cannot find class in same path.
By ribbs2521 in forum New To JavaReplies: 4Last Post: 05-07-2009, 05:25 PM -
trying to get class name & path
By sandor in forum New To JavaReplies: 4Last Post: 08-12-2008, 01:38 PM -
Setting up class path for Eclipse
By tsantana in forum EclipseReplies: 1Last Post: 04-07-2008, 07:05 PM -
Log4J.jar in class path
By eva in forum New To JavaReplies: 0Last Post: 01-02-2008, 06:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks