Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Can't execute Jar file: "Class not found exception"

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can't execute Jar file: "Class not found exception"

    I need to create an executable .jar file for my project. I managed to built it following the Oracle docs, using `jar cfm hangman.jar Manifest.txt src/classes/app/Main.class`. But I can't execute it, it keeps throwing me 'Could not find or load main class Main'. I would like some help in understanding what I'm doing wrong. Is it the wrong classpath or the main class?

    Here's it's tree:
    .
    ├── hangman.jar
    ├── Manifest.txt
    ├── README.md
    └── src
          ├── app
          │** ├── Main.java
          │** ├── Player.java
          │** ├── Players.java
          │** ├── Play.java
          │** ├── Themes.java
          │** ├── Word.java
          │** └── Words.java
          └── classes
              └── app
                  ├── Main.class
                  ├── Play.class
                  ├── Player.class
                  ├── Players.class
                  ├── Themes.class
                  ├── Word.class
                  └── Words.class
    The manifest holds these infos:
    Main-Class: Main
    Class-Path: src/classes/app
    Last edited by Norm; September 23rd, 2020 at 08:54 AM. Reason: Added code tags to better show tree

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,071
    Thanks
    53
    Thanked 2,614 Times in 2,564 Posts

    Default Re: Can't execute Jar file: "Class not found exception"

    Is the Main class in a package? If so the package name is part of the full class name that would be used in the manifest file and .class file needs to be in the folders representing the package it is in.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Re: Can't execute Jar file: "Class not found exception"

    I changed the Main-Class in the manifest to classes.app.Main, to include the package name as said. But I'm still receiving ClassNotFoundException, this time to classes.app.Main.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,071
    Thanks
    53
    Thanked 2,614 Times in 2,564 Posts

    Default Re: Can't execute Jar file: "Class not found exception"

    What package is the Main class in? Is the Main.class file loaded into the correct directory in the jar file?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: August 16th, 2014, 01:34 AM
  2. Replies: 3
    Last Post: August 14th, 2013, 04:23 PM
  3. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  4. Replies: 26
    Last Post: February 10th, 2013, 12:59 PM
  5. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM

Tags for this Thread