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 19 of 19

Thread: Eclipse | why my program closed (jar) ?

  1. #1
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Eclipse | why my program closed (jar) ?

    My Code:
    PHP Code:
    package test;
    import java.util.Scanner;
     
    public class 
    Test {
     
        public static 
    void main(String[] args) {
            
    Scanner in = new Scanner(System.in);
            
    System.out.println(System.getProperty("user.name"));
            
    System.out.println("Type -1 to exit");
            
    int close in.nextInt();
            while(
    close != -1) {
                
    System.out.println("Type -1 to exit");
                
    close in.nextInt();
            }
            
    in.close();
            
    System.exit(0);
        }

    its work on the console (run in eclipse)
    but when i export to desktop and double click it, it doesnt work

    in cmd:
    Microsoft Windows [Version 10.0.18362.356]
    (c) 2019 Microsoft Corporation. All rights reserved.

    C:\Users\doron>java -jar 1.jar
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.UnsupportedClassVersionError: test/Test has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)

    C:\Users\doron>
    Attached Images Attached Images
    • File Type: jpg 1.jpg (9.8 KB, 4 views)
    Last edited by doronbachar; September 19th, 2019 at 08:52 AM.

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Maybe tell us how you create the jar?
    Whatever you are, be a good one

  3. #3
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by John Joe View Post
    Maybe tell us how you create the jar?
    i hope you can help:
    https://streamable.com/jonee

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    uble click it, it doesnt work
    Try to get any error messages by running the jar file in a command prompt window.

    Open a command prompt window
    move to the directory containing the jarfile
    Enter the command: java -jar THEJARFILENAME.jar

    Copy the contents of the command prompt window and paste it here.

    Post text not an image. The posted image is not readable.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    Try to get any error messages by running the jar file in a command prompt window.

    Open a command prompt window
    move to the directory containing the jarfile
    Enter the command: java -jar THEJARFILENAME.jar

    Copy the contents of the command prompt window and paste it here.

    Post text not an image. The posted image is not readable.
    i did it already: https://streamable.com/jonee

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Post text not an image. The posted image is not readable.
    Sorry I do not click on links to other sites.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    Post text not an image. The posted image is not readable.
    Sorry I do not click on links to other sites.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    ok
    Microsoft Windows [Version 10.0.18362.356]
    (c) 2019 Microsoft Corporation. All rights reserved.

    C:\Users\doron>java -jar 1.jar
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.UnsupportedClassVersionError: test/Test has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)

    C:\Users\doron>

    --- Update ---

    Quote Originally Posted by Norm View Post
    Post text not an image. The posted image is not readable.
    Sorry I do not click on links to other sites.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    ok
    Microsoft Windows [Version 10.0.18362.356]
    (c) 2019 Microsoft Corporation. All rights reserved.

    C:\Users\doron>java -jar 1.jar
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.UnsupportedClassVersionError: test/Test has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)

    C:\Users\doron>

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Exception in thread "main" java.lang.UnsupportedClassVersionError: test/Test has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    You are using a younger version to compile the program and an older version to execute it. The older version does not work with the output from the younger version.
    Can you change the programs you are using so that the compiler version is the same age as or older than the execution version?

    To see what versions you are using, enter:
    javac -version
    java -version

    52 = Java 8; 53 = Java 9; 54 = Java 10; 55 = Java 11; 56 = Java 12

    See https://www.baeldung.com/java-lang-u...edclassversion for some ideas
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    You are using a younger version to compile the program and an older version to execute it. The older version does not work with the output from the younger version.
    Can you change the programs you are using so that the compiler version is the same age as or older than the execution version?

    To see what versions you are using, enter:
    javac -version
    java -version

    52 = Java 8; 53 = Java 9; 54 = Java 10; 55 = Java 11; 56 = Java 12

    See https://www.baeldung.com/java-lang-u...edclassversion for some ideas
    Microsoft Windows [Version 10.0.18362.356]
    (c) 2019 Microsoft Corporation. All rights reserved.

    C:\Users\doron>javac -version
    javac 12.0.2

    C:\Users\doron>java -version
    java version "1.8.0_221"
    Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
    Java HotSpot(TM) Client VM (build 25.221-b11, mixed mode)

    C:\Users\doron>

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Ok, you need either to upgrade the java program to 12 or to downgrade the javac program to 8.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    Ok, you need either to upgrade the java program to 12 or to downgrade the javac program to 8.
    Sorry about the ignorance
    i have 2 java apps on my pc:
    1. Java 8 Update 221
    2. Java(TM) SE Development Kit 12.0.2
    who is the old version ? and what install instead
    Last edited by doronbachar; September 19th, 2019 at 09:07 AM.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    8 is the older version.
    12 is the newer version.

    How did you get those two versions?

    Is one a JRE (no javac program)
    and one the JDK? (has the javac program)
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    8 is the older version.
    12 is the newer version.

    How did you get those two versions?

    Is one a JRE (no javac program)
    and one the JDK? (has the javac program)
    now i delete and this what he show:
    Microsoft Windows [Version 10.0.18362.356]
    (c) 2019 Microsoft Corporation. All rights reserved.

    C:\Users\doron>javac -version
    javac 12.0.2

    C:\Users\doron>java -version
    java version "12.0.2" 2019-07-16
    Java(TM) SE Runtime Environment (build 12.0.2+10)
    Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)

    C:\Users\doron>

    i delete the jar file and export again yet doesnt work

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    What happens when you open a command prompt window and enter:
    java -jar THEJARFILENAME.jar

    If you open the File Explorer program and look at the contents of the folder with the jar file,
    what is shown in the Type column for the jar file?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    What happens when you open a command prompt window and enter:
    java -jar THEJARFILENAME.jar

    If you open the File Explorer program and look at the contents of the folder with the jar file,
    what is shown in the Type column for the jar file?
    now after i delete the version of java:
    when i type: java -jar 1.jar
    its open and work!
    but why i need to do cmd-> type: java -jar 1.jar ?
    why its not open when i double click the jar file (have icon of java and its jar filr in file explorer)

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    What about this?
    If you open the File Explorer program and look at the contents of the folder with the jar file,
    what is shown in the Type column for the jar file?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    What about this?
    I wanted the input that needed to be clicked to not closing the window.
    But when i double click the JAR File, its not opening.
    That mean even input doesnt help ? just GUI ?
    I try simple GUI and create JAR when i double click it ts work!.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    I try simple GUI and create JAR when i double click it ts work!.
    Yes, code that only uses the console won't be seen if it is executed from a jar file. It needs to use GUI.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Eclipse | why my program closed (jar) ?

    Quote Originally Posted by Norm View Post
    Yes, code that only uses the console won't be seen if it is executed from a jar file. It needs to use GUI.
    thank you for your help and your time

Similar Threads

  1. Replies: 21
    Last Post: June 12th, 2013, 11:33 AM
  2. How do you make a console program a .jar in Eclipse?
    By Programmer142 in forum Java Theory & Questions
    Replies: 9
    Last Post: January 13th, 2012, 12:13 AM
  3. How to make a program into a working .jar? (eclipse)
    By ynnad95 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2011, 08:29 PM
  4. Creating JAR file in eclipse HELP !
    By Maheshkh in forum Java IDEs
    Replies: 3
    Last Post: September 16th, 2011, 12:37 PM
  5. Jar Versioning with Eclipse
    By KevinWorkman in forum Java IDEs
    Replies: 4
    Last Post: July 12th, 2011, 05:49 PM