0

I have a ReadMail.java in d:/folder1/myfolder location.

I require 2 jars files also namely, javax.mail.jar and activation.jar which i have saved in d:/folder1.

I am able to compile without any errors through command prompt using below command:

javac -cp D:/folder1/myfolder/javax.mail.jar;D:/folder1/myfolder/Java_mail/activation.jar ReadMail.java

java -cp D:/folder1/myfolder/javax.mail.jar;D:/folder1/myfolder/Java_mail/activation.jar ReadMail

I am getting "Could not find or load main class ReadMail" error. Could someone point out the mistake I have done?

ozata
  • 542
  • 1
  • 5
  • 16
Devjith
  • 19
  • 4

1 Answers1

1

You are just typing Java ClassName. You need to give it the entire package name. CD to the root of your package and type:

java -cp D:/folder1/myfolder/javax.mail.jar;D:/folder1/myfolder/Java_mail/activation.jar EntirePackageName.ReadMail

JohanLarsson
  • 195
  • 1
  • 7
  • Mycode starts with imports only. How should I add the package name inside the java file? – Devjith Aug 13 '18 at 08:59
  • Then your class belongs to the "unnamed package". I think the correct approach then is to cd to the folder where the file is and type Java ClassName like you did, I'm not sure though. You will have to search how to run .Java files that belong to the "unnamed package", OR you will have to learn how Java uses packages. I suggest the latter since that is necessary to understand Java. Ignore your programming and running the class for now, and learn about Java packages and "namespacing". – JohanLarsson Aug 13 '18 at 09:41