Q:

Java: Class not found in Unix

am trying to run a Java file on Unix machine. Let me show the directory structure first:
/home/username
  |_ SimpleMail.java
  |_ mail.jar

I have compiled the java code using: 
# javac -classpath mail.jar SimpleMail.java

After compiling that, directory has:
/home/username
      |_ SimpleMail.java
      |_ mail.jar
      |_ SimpleMail.class

Now I tried to run that SimpleMail class file. That is giving Class not found error:
I have tried to run the class using:
# java -classpath mail.jar SimpleMail

Error:
The java class is not found:  SimpleMail

Whats wrong in that process?
Thanks :)

A:

You need to include the current directory on the classpath too, in order to pick up the classfile there:
java -classpath mail.jar:. SimpleMail

That will work if SimpleMail isn't in a package. Otherwise you should compile with -d . and include the package name when you're running java:
javac -d . -classpath mail.jar SimpleMail.java

java -classpath mail.jar:. my.pkg.SimpleMail

