Im writing a Java Application and I wanted to create a Package so since the name of my main class is called Messenger I called the Package MessengerPack.  I created a directory called MessengerPack and put my files (2 of them) inside of the directory.  

At the top of both files I put...

package MessengerPack;
import java.awt.*;
import java.awt.event.*;

I setup my Classpath to include the Java run time interpreter's directory and the folder that contains my MessengerPack folder.

So d:\studio\myprojects\MessengerPack
set ClassPath=d:\studio\myprojects

Everything compiles OK but when I run my application the Interpeter cannot find the Messenger class.

I can't seem to figure out why it wont find it.  I tried running the program from inside the MessengerPack folder with no luck.  I get the exception...

java.lang.NoClassDefFoundError: Messenger
Exception in thread "main" Exit code: 1
There were errors

If anyone knows what I missed I could use the help.  Im using jdk 1.2.2
Could it be that Im using the wrong path to the JRE?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

are u using
java MessengerPack.Messenger
Try 1:
      Go to the directory holding the
     Eg.  d:\studio\myprojects
      Execute the application,
  java MessengerPack.Messenger.

Try 2:
       Please recheck the classpath


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmaroffAuthor Commented:
Vichu, what would I need to put in the classpath so I can just type:

java Messenger
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

there's no way...
Messenger is part of the package MessengerPack that's y u need to invoke the class like that...
u could remove Messenger from MessengerPack...
lychee's comment is correct.We have to
execute the application like that only
because the class Messenger is a part of
the MessengerPack package.If you still
want to execute your application like
java Messenger, remove the Messenger class from the package by removing the
"package Messenger;" in your code.
I think, the above will solve your problem.

dmaroffAuthor Commented:
Thanks, I upped the points to to 150 cause you've been a big help.  I just have 2 last questions, if you don't mind.  

In C++ I can have seperate .c files and compile them together into 1 executable.  I want to have the same in my java program, but the only way I know how is through making a package and putting all the files in the package.  Every class that I made has its own file and at the top of it has the "package MessengerPack", is this the correct way to go about this?  I might end up with 6 different classes, but I don't want 1 huge file.  Thats the only reason I used a package in the first place.  

Also if I want to distribute my program, does the person's classpath variable have to be set like mine, and would it be any easier to just package all the class files into a .jar file so it would execute like one big executable?

Thanks for all your help,
the idea of packages is to eliminate class name conflicts (where 2 classes have the same name) and also for a logical grouping of classes... as for putting the files into 1 file, u'd have to use a jar file... for distribution, u should use a jar file, since data compression is used and so it'll be smaller... then for ur clients to use ur program, if they use:

java 1.1:
jre -cp xxxxx.jar Messenger
(if u pulled Messenger into the default package; otherwise it'll still be MessengerPack.Messenger)

java 2:
java -jar xxxxx.jar

u should include a manifest file in ur jar file that includes the line:

Main-Class: Messenger

and ur jar file should contain the same directory structure as ur current development directory, as in u should have a MessengerPack directory in the jar file that contains the classes that belong to the package MessengerPack...
dmaroffAuthor Commented:
But what if the classes have different names so there are no name conflics, do I still need a package?  If not how would I get one file to 'see' the next?  Also is there a good book or web site that explains all of this housekeeping?  It seems now that Java has a lot more housekeeping than C++.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.