wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes package/directory stuff Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package/directory stuff" Watch "package/directory stuff" New topic
Author

package/directory stuff

Patrick Tibbetts
Greenhorn

Joined: Jan 06, 2002
Posts: 20
Hi everyone!
I am so frustrated.
I can not get my classes to work at runtime if I use a package declaration.
ie:
package whatever;
class thing
{
//some code
//main()
}
I can get it to compile just fine. However if I take the package statement out this would run fine.
I have my classpath set at the end of the path as ;c\jdk1.3.1_02\bin;
I am thinking my problem is that i have my OS and data on 2 different partitions(c/d). Should I add another path get the package declarations to work at runtime???
The error is:
Exception in thread "main" java.lang.NoClassDefFoundError: className (wrong name: packageName/className)
I am using XP, jdk1.3
Thanks!
-patrick
[ August 17, 2002: Message edited by: Patrick Tibbetts ]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi,
Do make sure that u r using the full name of the class when u run it.
If ur class Mycls is in the package Mypkg, you have to save it in a directory called Mypkg.
To run it you need to go one level above the Mypkg directory, and run the interpreter as
java Mypkg.Mycls
Hope this helps


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Patrick Tibbetts
Greenhorn

Joined: Jan 06, 2002
Posts: 20
Sandeep,
Thanks.
Yes I have done that. I still get that same error, only without the stacktrace =-)

if my package is "packages" and my class is "myClass":
From the command prompt:
d:\packages>javac myClass.java //to compile
d:\packages>java myClass //to run it.
That is what I am doing. I did do the:
d:\packages>java packages.myClass
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
Patrick,
You need add your folder d: to the classpath.
it's not able to find the class in the classpath defined by you.
Just add d: to classpath, I guess then it should start rolling.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
if my package is "packages" and my class is "myClass":
From the command prompt:
d:\packages>javac myClass.java //to compile
d:\packages>java myClass //to run it.
That is what I am doing. I did do the:
d:\packages>java packages.myClass

That won't work unless d:\ is in your classpath as shiv suggested.
If you don't want d:\ in you classpath, then do as Sandeep suggested, go one level above (or below - however you want to think of the tree structure) your package to the d:\ folder (the root folder of the d drive) and try to execute your application like this: java packages.myClass .
[ August 17, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Patrick Tibbetts
Greenhorn

Joined: Jan 06, 2002
Posts: 20
Thanks all!
I did reset my classpath.
I should have know better... :roll:
Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: package/directory stuff
 
Similar Threads
urgent websphere 3.5 and response.sendRedirect
JacORB. Eclipse and alternative to Xbootclasspath/p .... ?
Compiling through Servlet
importing custom class/method into servlet; servlet and finding classpath?
javadoc problems