Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package/directory stuff

 
Patrick Tibbetts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Patrick Tibbetts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Patrick Tibbetts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all!
I did reset my classpath.
I should have know better... :roll:
Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic