user3583094
user3583094

Reputation: 105

Trying to compile code - Could not find or load main class a

So I've looked up many tutorials on how to compile code. I've tried to follow all of them. But I keep getting that error. Here's my code:

package ytho;

public class a {
    public static void main(String[] args){
    System.out.println("ytho");
    }


}

And here's what I put for my manifest.txt:

Main-Class: a

I've also tried putting it as Main-Class: .a and Main-Class: ytho.a, to no avail. I'm sorry that this is a duplicate, but all other tutorials on here haven't worked for me. So, I decided to finally ask myself. Help would be greatly appreciated. And if you need more information, let me know, but I may be late to reply.

Upvotes: 2

Views: 326

Answers (2)

Cripto
Cripto

Reputation: 3751

Lets do it step my step:

  1. Create a folder with your package name
  2. Rename your a class to A since java uses Capitals on the first letter (this is stylistic)
  3. Compile your file javac ytho/A.java
  4. Create the jar jar cvfm MyJarName.jar MANIFEST.MF *

Here is what my directory looks like

.
├── MANIFEST.MF
├── MyJarName.jar
└── ytho
    ├── A.class
    └── A.java

Here is the content of the Manifest

Main-Class: ytho.A

And run it like so:

$: java -jar MyJarName.jar 

which print out

ytho

Upvotes: 2

pczeus
pczeus

Reputation: 7868

In your manifest, you are missing the package in your classname:

Main-Class: ytho.a

See this link for more details: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Also, you should not name your class with all lowercase (or a single character for that matter).Call it something meaninful like JarTest.class or something

Upvotes: 0

Related Questions