Search code examples
classintellij-ideajarprogram-entry-point

IntelliJ build wrong JAR: Could not find or load main class


I have a simple example

public class FileSystemReadFile {
    public static void main(String[] args) throws IOException {
        System.out.println("Reading the file" + args[0]);
    }
}

which is created in IntelliJ where I want to build JAR file; So what I did:

  1. Added Artifact with dependencies (presumably I have some);
  2. Ensure that MANIFEST.MF is located in src\main\resources\META-INF\ as it is already mentioned somewhere here on the site.
  3. Run Artifact build which gave me JAR file in out folder and I run that jar file that said me "Could not find or load main class"
    java <name>.jar

You may see that main class is added into MANIFEST and location of manifest is also fine.

Project structure

When I open that created JAR file, I see the same MANIFEST content, I see lots of dependency modules, but I don't see my class!

enter image description here

I suspect that is a cause. Any ideas?


Solution

  • Not sure what was with IntellJ, but I rebuilded artifacts again and it was ok.

    hadoop jar <Jar-name>
    java -jar <Jar-name>
    

    Everything is working fine.