Results 1 to 4 of 4
- 02-05-2012, 07:32 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
NoClassDefFoundError: packages and the classpath
So i have a simple program, basically i have a ProjectileMotion.java source file that includes a class which does some simple calculation for projectiles, I compiled it into a class file, and its in a package Program.Physics.Kinematics.
I then created a small test.java source file meant to use the ProjectileMotion class from that package, and I put this test.java file in dir Program...
SO:
ProjectileMotion.class is in ~/Programming/Java/Program/Physics/Kinematics
test.java is in ~/Programming/Java/Program
The test file imports Program.Physics.Kinematics.ProjectileMotion in its source, so i can use the unqualified names. I then compiled it:
javac -cp ~/Programming/Java test.java
It worked fine, but then when i try to run it:
java test
I get something starting like this:
Exception in thread "main" java.lang.NoClassDefFoundError: Program/Physics/Kinematics/ProjectileMotion
at test.main(test.java:9)
Caused by: java.lang.ClassNotFoundException: Program.Physics.Kinematics.ProjectileMotion
........
(it then lists more stuff)
I figure I must be doing something wrong with my CLASSPATH variable, my use of Packages, or my call to java when i run it, but I've spent hours searching for an answer and haven't found one yet.
Thanks in advance for the help.
- 02-05-2012, 09:57 PM #2
Re: NoClassDefFoundError: packages and the classpath
Your Program.Physics.Kinematics.ProjectileMotion class must be on the classpath for the java program to find it.
If the Program folder is in the same folder as the test.class file and the default classpath of . (a dot) is not overridden by the CLASSPATH environment variable, the java program should be able to find it. Otherwise you need to tell the java program where it is located by using the classpath option.
- 02-05-2012, 10:48 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Re: NoClassDefFoundError: packages and the classpath
Excellent! I moved my test.class up to the parent directory, so it was right above the package path and now it works.
So I guess the problem was that I had my test.class within the package path (actually parallel with the top of it) when I tried to run it?
Also, thank you very much for the help!
- 02-05-2012, 10:53 PM #4
Similar Threads
-
what is runtime classpath and what is designtime classpath?
By LongTTH in forum New To JavaReplies: 1Last Post: 05-03-2011, 02:28 AM -
NoClassDefFoundError
By Josisco in forum JDBCReplies: 2Last Post: 10-30-2010, 08:07 PM -
noClassDefFoundError
By imorio in forum EclipseReplies: 11Last Post: 08-21-2010, 07:45 PM -
NoClassDefFoundError
By Dbirge in forum New To JavaReplies: 0Last Post: 03-16-2010, 05:01 PM -
Importing packages from the packages within same application.
By sta2003 in forum New To JavaReplies: 3Last Post: 02-12-2008, 11:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks