Results 1 to 8 of 8
  1. #1
    Igbear is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default Got problem with jar-file, any help?

    Hello.
    I've been learning java through my study for the past few months, so I'm not new to it anymore, still I don't know if this is considered to be advanced. Anyway, let's have a go:

    I am trying to make a jar-file for the first time, so that Windows-users may run the file without using Textpad

    So far, I've tried followed the necessary(?) hints in the internet, and it's still not working.
    The file is called maria.class

    This is the manifest.txt:
    Main-Class: package.maria


    And yes, I'm aware of following rule:
    "Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return."
    So I've typed in an open line below the text.

    Then I've have typed the following commands in command prompt:
    echo Main-Class: maria >manifest.txt
    jar cvfm maria.jar manifest.txt maria.class

    When I try to open the maria.jar file, I get this message in return:
    Could not find the main class: maria. Program will exit

    Any ideas of how to solve this?

    And yes, I got java SDK installed, and I've set the path to SDK's bin folder.
    And yes, I got a main-method in the class file.

    Any help would be great.

  2. #2
    Igbear is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default

    Actually,
    "This is the manifest.txt:
    Main-Class: package.maria"

    is not what I've usually tried.
    it's been either
    Main-Class: maria or Main-Class: maria.class
    I wrote package in front in one of the attempts, and forgot to remove it after that attempt

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Since there's a lot of bogus stuff about on the internet I would suggest, if you haven't read it, Oracle's Tutorial section on Setting an Application's Entry Point.

    The line should specify maria not maria.class. (And, please, change and recompile it as Maria.)

    I wouldn't bother using echo to create the manifest when you already have Textpad open. Create manifest.txt with exactly the content you mean it to have and save it.

    You don't actually say whether the class is part of a package or not. If it is then you have to mention that package as part of the class's name in the manifest. (See link above)

    ---------------

    Sorry - totally wrong garbage posted here.
    Last edited by pbrockway2; 11-20-2010 at 12:17 AM.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You might want to post maria.java if it's not huge. Not that anyone mistrusts what you posted, but many eyes might spot something concerning packages or the entry method declaration.

  5. #5
    Igbear is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default Sure

    I suppose I could post the entire class, it's only a main one.
    Though I'm not fully sure whether I understand correctly what it means when it's about package. Is that all the sub-folders all the way until you "find" the actual file, or am I off track?

    /*
    *maria.java
    */
    import static javax.swing.JOptionPane.*;
    import java.util.Random;

    class Maria{
    public static void main(String[] args){
    String tallLest = showInputDialog("Skriv et tall mellom 1 og 30");
    int tall = Integer.parseInt(tallLest);
    while (tall<1 || tall>30){
    if (tall<1){
    tallLest = showInputDialog("Du har skrevet et tall under 1. Skriv på nytt \nSkriv et tall mellom 1 og 30");
    }
    if (tall>30){
    tallLest = showInputDialog("Du har skrevet et tall over 30. Skriv på nytt \nSkriv et tall mellom 1 og 30");
    }
    tall = Integer.parseInt(tallLest);
    }
    java.util.Random tallGen = new java.util.Random();
    String[] setninger = {"Du er rå!", "Du er bra!", "Vi digger deg!", "Bli frisk igjen, Maria!", ":)",
    "Ikke gi opp!", "Gud elsker deg så utrolig høyt!", "Lys i enden av tunnellen finnes", "Stå på!", "Du er tøff",
    "Herren er din Hyrde", "Jesus elsker alle barna!...også Maria!", "Hurra!", "Du er veldig flink til å synge.", "Kanskje du en dag produserer egen plate?",
    "Du er vakker", "Fin jente", "Skapt i Guds bilde", "Underfull skapt", "Unik",
    "Ingen er som du!", "Turn your eyes upon Jesus", "Han slipper deg ikke", "Vi digger digger digger digger deg!", "Yehaa",
    "Du har fint hår", "Smil, Gud elsker deg!", "Du er prinsesse!", "1, 2, 3, hipp hurra for fantastiske Maria!", "You rock"};
    String[] utskrift = new String[tall];
    int i = 0;
    while (i<setninger.length && i<tall){
    boolean allerede = false;
    int plukkTall = tallGen.nextInt(30);
    for (int a = 0; a<utskrift.length; a++){
    if (setninger[plukkTall]==utskrift[a]){
    allerede=true;
    }
    }
    if (allerede==false){
    String nySetning=setninger[plukkTall];
    utskrift[i]=nySetning;
    i++;
    }
    }
    String utskriftSetning = "";
    for (int e = 0; e<utskrift.length; e++){
    utskriftSetning+=utskrift[e]+"\n";
    }
    showMessageDialog(null, utskriftSetning);
    }
    }

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The concept of package may be related to subfolders, but it's something that must be explicitly declared in your class. Your class does not belong to a package, so we can rule that out as the problem.

    I note that your class is Maria with a capital M, but that the comment at the start mentions maria.java as being the file (and your jar command uses maria.java). You have to be completely consistent about this. The file should be Maria.java and the jar command should be

    Java Code:
    jar cvfm maria.jar manifest.txt Maria.class

    The manifest.txt would be

    Java Code:
    Main-Class: Maria

    (with a blank line at the end)

    Could you check all this and post the output from the jar command?

  7. #7
    Igbear is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default

    Hey, it worked! Thanks!

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. .BAT File problem
    By egbert95 in forum New To Java
    Replies: 8
    Last Post: 08-03-2010, 02:26 AM
  2. Jar File Problem
    By Moncleared in forum New To Java
    Replies: 10
    Last Post: 10-18-2009, 08:43 AM
  3. jar file problem
    By nishant.4545 in forum New To Java
    Replies: 1
    Last Post: 07-03-2009, 09:36 PM
  4. problem - using a jar file
    By jon80 in forum New To Java
    Replies: 6
    Last Post: 07-07-2008, 08:49 AM
  5. problem with jar file pls help
    By jinu5 in forum New To Java
    Replies: 0
    Last Post: 08-15-2007, 11:41 PM

Tags for this Thread

Posting Permissions

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