my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Packages" Watch "Packages" New topic
Author

Packages

Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
I wrote this simple program in a package and my directory structure is E:\Java\folder and my main class is inside folder package...the code of the program is



When I'm trying to run this program from the current directory as folder...it gives me NoClassDefFoundError....Any help guys.....


Human Knowledge Belongs to the World.
- Vasiq Mz
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
First, if it compiles, the underlying package/folder structure should be fine.

Are you trying to run your program from the 'folder' folder or from the project's root path?


JDBCSupport - An easy to use, light-weight JDBC framework -
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
I'm running this class from the "folder" folder and even if I try to run it from Java folder which the parent directory of "folder"..it doesn't work...but there was no error while compiling....why at runtime..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Most likely you're specifying the classpath incorrectly. Without knowing how you're *actually* trying to run it, though, it's impossible to help.
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
David Newton wrote:Most likely you're specifying the classpath incorrectly. Without knowing how you're *actually* trying to run it, though, it's impossible to help.


My directory structure where I stored this program is
E:
|
----->Java
|
-------->folder
|
------>Package.java

and I'm running the program from the folder package....it compiles fine but at runtime it gives an NoClassDefFoundError....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Again, can't you just post the exact command line you're using? We cannot possibly know what you're doing wrong unless you TellTheDetails.

That said, don't run it from the "folder" directory, but the one above it.
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
David Newton wrote:Again, can't you just post the exact command line you're using? We cannot possibly know what you're doing wrong unless you TellTheDetails.

That said, don't run it from the "folder" directory, but the one above it.


This is what I'm getting after I tried to run the program.
E:\Java\folder>java PackageTest
Exception in thread "main" java.lang.NoClassDefFoundError: PackageTest (wrong name: folder/PackageTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$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)
Could not find the main class: PackageTest. Program will exit.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Did you not see the second sentence in my response?

You still need to either specify the classpath (or, less preferentially, rely on the default, which I *think* is ".", hence why I told you to run it from a different directory).
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
David Newton wrote:Did you not see the second sentence in my response?

You still need to either specify the classpath (or, less preferentially, rely on the default, which I *think* is ".", hence why I told you to run it from a different directory).


It's working perfectly now..thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Packages