Results 1 to 5 of 5
  1. #1
    gio123bg is offline Member
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    Default Problem executing jar file

    Hi All,
    I'm trying to execute a jar file in this way:
    java -jar HelloWorld.jar

    but I receive this error message.
    Failed to load Main-Class manifest attribute from HelloWorld.jar

    I have two source java code:
    public class HelloWorld1 {
    public static void main(String[] args) {
    System.out.println("Hello World #1");
    }
    }
    and
    public class HelloWorld2 {
    public static void main(String[] args) {
    System.out.println("Hello World #2");
    }
    }

    I have created a manifest file named HelloWorld.mf containing this text.
    Main-Class: HelloWorld1

    I have created the jar file in this way.
    jar cmf HelloWorld.mf HelloWorld.jar HelloWorld1.class HelloWorld2.class

    Any Idea?
    Any help will be well appreciated.
    Thanks in advance.
    Regards,

    Giovanni

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    not too sure why, but try this command:
    Java Code:
    jar -efc HelloWorld1 HelloWorld.jar *.class
    
    //  jar -efc {Main-Class} {Jar-Name} {.class-files}
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    7

    Default

    You main fest file of the jar should have the class name which would run first in your application.I think you did not do it. Use any IDE such as NEtBeans to create jar file.
    If you dont have IDE follow the way of angry boy.
    Mak
    (Living @ Virtual World)

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Do you have a new line after Main-Class: HelloWorld1?
    You need a NL or jar will strip it off.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    gio123bg is offline Member
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    Default

    Thanks! I solved my problem. The NL was the problem.
    Regards,

    Giovanni

Similar Threads

  1. Executing a jar file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 02-14-2014, 10:02 AM
  2. Problem executing .exe file created with C++ code
    By Singing Boyo in forum Advanced Java
    Replies: 45
    Last Post: 05-30-2009, 01:39 AM
  3. Problem with executing
    By mcal in forum New To Java
    Replies: 2
    Last Post: 02-09-2008, 02:51 PM
  4. executing the java file
    By TheBayWatchMan in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:31 AM
  5. Problem with executing .jar files
    By hiranya in forum NetBeans
    Replies: 2
    Last Post: 10-02-2007, 08:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •