Reputation: 51
How I can run java program using command prompt? I already run my program using command prompt but i get this error Could not find or load main class ReadWriteTextFile
Upvotes: 0
Views: 1524
Reputation: 1493
Check your entry point specification in your manifest as explained here:
You should set an entry like this one:
Main-Class: YourPackage.ReadWriteTextFile
Maybe the package path is missing? I got myself this kind of issue when launching jar files... I hope this helps.
Upvotes: 0
Reputation: 5208
Well, there are a few conditions on running a java class:
First of all, the file you want to run should have a public class, with the same name as the file. For instance, Test.java
would contain the Test
class.
The public class should have a main method. This is a static method. It's arguments are the command line arguments passed. It's signature must be public static void main(String[] args)
.
As an example class you can call from the command line:
public class ReadWriteTextFile {
public static void main(String[] args) {
readWriteTextFile();
}
public static void readWriteTextFile() {
// Do stuff.
}
}
If saved in the file ReadWriteTextFile.java
, you can compile and call it like this:
$ javac ReadWriteTextFile.java
$ java ReadWriteTextFile
$
Seen from the error message you get, your file is probably called ReadWriteTextFile
, but you haven't got a public ReadWriteTextFile class with a main
method in it.
Upvotes: 1