Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

core java creating package exception

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package P;
class Example
{
public static void main(String args[])
{
System.out.println("creating package p");
}
}

i compiled this with

javac -d . Example.java

and made it run with

java Example


but it gave me an exception classNot found

why is it doing so??
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a) the class is not named "Example", it is named "P.Example", and b) the class file is in the wrong location - it should be in a subdirectory called "P". You may want to read up on packages: http://java.sun.com/docs/books/tutorial/java/package/index.html
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try java P.Example

Have a look at the Java™ Tutorials and search this forum for "compiling package" where you should find at least three ways to compile classes with package names.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf, it is only Rob who is allowed to beat my by two minutes like that
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I promise to do worse in the future :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic