Skip to content
Advertisement

Can’t run java application with .jar dependancy – ‘Error: Could not find or load main class’

So my code runs fine in my IDE and I have the javax.mail.jar set as a dependency and my code runs fine.

Except I need to use Console console = System.console(); and this does not work within IDE’s

So I am trying to compile my code and run it via the terminal, I can compile although when running my code it returns the error:

Error: Could not find or load main class Main

This is what I do to compile:

javac -cp “./javax.mail.jar” Main.java

Then to run it:

java -cp “./javax.mail.jar” Main

but I get the Error: Could not find or load main class Main

This is my full code:

JavaScript

Edit: Also tried running from parent directory(This has my com folder in and the java.mail.jar):

java -cp “./javax.mail.jar;.” com.company.Main

But I get this:

Error: Could not find or load main class com.company.Main

Advertisement

Answer

You shall compile it from parent folder of com, by:

JavaScript

And then run by

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement