Packaging Jar file for Mac and Windows without JRE bundled












4














I built in IntelliJ IDEA my javaFX application as jar file.
Using "Project Structure >> Artifacts >> + JavaFX Application" I can build .app, .dmg, .pkg, .exe with JRE included.
But I need build same files without JRE bundled.
Sure, I can use JAR, but I want to make my own icon and maybe installer.



I also tried to create .app folder from jar to execute it manually "java -jar myJarName.jar" , but if I have several JDK version - it always uses the latest (JRE 11) which not included javaFX library and my .app doesn't work. But if I run the same JAR with Jar Launcher.app it works perfectly. Somehow it chooses the right jre version.
ExcelsiorJet, install4j and similar apps work well, but my project is OpenSource and I can not pay 3000$ for this.



The question is - how can I build MacOs/Windows native launcher app/dmg/pkg/exe without JRE bundled for users who already have JRE installed? Can I use IntelliJ IDEA to build this a way as I built with jre bundled?










share|improve this question





























    4














    I built in IntelliJ IDEA my javaFX application as jar file.
    Using "Project Structure >> Artifacts >> + JavaFX Application" I can build .app, .dmg, .pkg, .exe with JRE included.
    But I need build same files without JRE bundled.
    Sure, I can use JAR, but I want to make my own icon and maybe installer.



    I also tried to create .app folder from jar to execute it manually "java -jar myJarName.jar" , but if I have several JDK version - it always uses the latest (JRE 11) which not included javaFX library and my .app doesn't work. But if I run the same JAR with Jar Launcher.app it works perfectly. Somehow it chooses the right jre version.
    ExcelsiorJet, install4j and similar apps work well, but my project is OpenSource and I can not pay 3000$ for this.



    The question is - how can I build MacOs/Windows native launcher app/dmg/pkg/exe without JRE bundled for users who already have JRE installed? Can I use IntelliJ IDEA to build this a way as I built with jre bundled?










    share|improve this question



























      4












      4








      4


      1





      I built in IntelliJ IDEA my javaFX application as jar file.
      Using "Project Structure >> Artifacts >> + JavaFX Application" I can build .app, .dmg, .pkg, .exe with JRE included.
      But I need build same files without JRE bundled.
      Sure, I can use JAR, but I want to make my own icon and maybe installer.



      I also tried to create .app folder from jar to execute it manually "java -jar myJarName.jar" , but if I have several JDK version - it always uses the latest (JRE 11) which not included javaFX library and my .app doesn't work. But if I run the same JAR with Jar Launcher.app it works perfectly. Somehow it chooses the right jre version.
      ExcelsiorJet, install4j and similar apps work well, but my project is OpenSource and I can not pay 3000$ for this.



      The question is - how can I build MacOs/Windows native launcher app/dmg/pkg/exe without JRE bundled for users who already have JRE installed? Can I use IntelliJ IDEA to build this a way as I built with jre bundled?










      share|improve this question















      I built in IntelliJ IDEA my javaFX application as jar file.
      Using "Project Structure >> Artifacts >> + JavaFX Application" I can build .app, .dmg, .pkg, .exe with JRE included.
      But I need build same files without JRE bundled.
      Sure, I can use JAR, but I want to make my own icon and maybe installer.



      I also tried to create .app folder from jar to execute it manually "java -jar myJarName.jar" , but if I have several JDK version - it always uses the latest (JRE 11) which not included javaFX library and my .app doesn't work. But if I run the same JAR with Jar Launcher.app it works perfectly. Somehow it chooses the right jre version.
      ExcelsiorJet, install4j and similar apps work well, but my project is OpenSource and I can not pay 3000$ for this.



      The question is - how can I build MacOs/Windows native launcher app/dmg/pkg/exe without JRE bundled for users who already have JRE installed? Can I use IntelliJ IDEA to build this a way as I built with jre bundled?







      java bash javafx jar






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 5:35

























      asked Nov 10 at 19:30









      Iga

      335




      335
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Okay, looks like I found some crooked way to do this all.




          Windows solution:




          To bundle on Windows it's easy to use launch4j (windows only). It's free and there is no problem to create .exe with no Jre bundled.




          MacOS solution:




          For MacOS it's a bit harder:





          1. Create myApplication.app folder and design it's structure



            enter image description here



          2. Write launcher bash script:
            In my case I should detect which versions of Jre installed and choose any between java 1.8 and 10



          I don't know bash script language and I believe I write it unoptimized way. I would be happy if anyone correct me. Anyway it works the way as I wanted:




          #!/bin/sh

          # set the working directory
          DIR=$(cd "$(dirname "$0")"; pwd)

          # extract first fit java version installed
          jre_path=$(/usr/libexec/java_home -V 2>&1 |
          while IFS= read -r line
          do
          if [[ "$jre_found" == "true" ]]; then
          break
          fi
          version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
          major=$(echo $version | cut -d. -f1)
          minor=$(echo $version | cut -d. -f2)
          array=(${line// /})
          array_size=${#array[@]}
          let "last_index=array_size-1"
          path=${array[ $last_index ]}

          if [[ $major == 1 ]]; then
          if [[ $minor -gt 7 && $minor -lt 11 ]]; then
          echo $path
          jre_found="true"
          fi
          elif [[ $major -gt 7 && $major -lt 11 ]]; then
          echo $path
          jre_found="true"
          fi
          done)

          # execute our jar file
          $jre_path/bin/java -jar "$DIR"/myApp.jar


          And now everything should be working from double click on myApplication.app.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242661%2fpackaging-jar-file-for-mac-and-windows-without-jre-bundled%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Okay, looks like I found some crooked way to do this all.




            Windows solution:




            To bundle on Windows it's easy to use launch4j (windows only). It's free and there is no problem to create .exe with no Jre bundled.




            MacOS solution:




            For MacOS it's a bit harder:





            1. Create myApplication.app folder and design it's structure



              enter image description here



            2. Write launcher bash script:
              In my case I should detect which versions of Jre installed and choose any between java 1.8 and 10



            I don't know bash script language and I believe I write it unoptimized way. I would be happy if anyone correct me. Anyway it works the way as I wanted:




            #!/bin/sh

            # set the working directory
            DIR=$(cd "$(dirname "$0")"; pwd)

            # extract first fit java version installed
            jre_path=$(/usr/libexec/java_home -V 2>&1 |
            while IFS= read -r line
            do
            if [[ "$jre_found" == "true" ]]; then
            break
            fi
            version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
            major=$(echo $version | cut -d. -f1)
            minor=$(echo $version | cut -d. -f2)
            array=(${line// /})
            array_size=${#array[@]}
            let "last_index=array_size-1"
            path=${array[ $last_index ]}

            if [[ $major == 1 ]]; then
            if [[ $minor -gt 7 && $minor -lt 11 ]]; then
            echo $path
            jre_found="true"
            fi
            elif [[ $major -gt 7 && $major -lt 11 ]]; then
            echo $path
            jre_found="true"
            fi
            done)

            # execute our jar file
            $jre_path/bin/java -jar "$DIR"/myApp.jar


            And now everything should be working from double click on myApplication.app.






            share|improve this answer




























              1














              Okay, looks like I found some crooked way to do this all.




              Windows solution:




              To bundle on Windows it's easy to use launch4j (windows only). It's free and there is no problem to create .exe with no Jre bundled.




              MacOS solution:




              For MacOS it's a bit harder:





              1. Create myApplication.app folder and design it's structure



                enter image description here



              2. Write launcher bash script:
                In my case I should detect which versions of Jre installed and choose any between java 1.8 and 10



              I don't know bash script language and I believe I write it unoptimized way. I would be happy if anyone correct me. Anyway it works the way as I wanted:




              #!/bin/sh

              # set the working directory
              DIR=$(cd "$(dirname "$0")"; pwd)

              # extract first fit java version installed
              jre_path=$(/usr/libexec/java_home -V 2>&1 |
              while IFS= read -r line
              do
              if [[ "$jre_found" == "true" ]]; then
              break
              fi
              version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
              major=$(echo $version | cut -d. -f1)
              minor=$(echo $version | cut -d. -f2)
              array=(${line// /})
              array_size=${#array[@]}
              let "last_index=array_size-1"
              path=${array[ $last_index ]}

              if [[ $major == 1 ]]; then
              if [[ $minor -gt 7 && $minor -lt 11 ]]; then
              echo $path
              jre_found="true"
              fi
              elif [[ $major -gt 7 && $major -lt 11 ]]; then
              echo $path
              jre_found="true"
              fi
              done)

              # execute our jar file
              $jre_path/bin/java -jar "$DIR"/myApp.jar


              And now everything should be working from double click on myApplication.app.






              share|improve this answer


























                1












                1








                1






                Okay, looks like I found some crooked way to do this all.




                Windows solution:




                To bundle on Windows it's easy to use launch4j (windows only). It's free and there is no problem to create .exe with no Jre bundled.




                MacOS solution:




                For MacOS it's a bit harder:





                1. Create myApplication.app folder and design it's structure



                  enter image description here



                2. Write launcher bash script:
                  In my case I should detect which versions of Jre installed and choose any between java 1.8 and 10



                I don't know bash script language and I believe I write it unoptimized way. I would be happy if anyone correct me. Anyway it works the way as I wanted:




                #!/bin/sh

                # set the working directory
                DIR=$(cd "$(dirname "$0")"; pwd)

                # extract first fit java version installed
                jre_path=$(/usr/libexec/java_home -V 2>&1 |
                while IFS= read -r line
                do
                if [[ "$jre_found" == "true" ]]; then
                break
                fi
                version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
                major=$(echo $version | cut -d. -f1)
                minor=$(echo $version | cut -d. -f2)
                array=(${line// /})
                array_size=${#array[@]}
                let "last_index=array_size-1"
                path=${array[ $last_index ]}

                if [[ $major == 1 ]]; then
                if [[ $minor -gt 7 && $minor -lt 11 ]]; then
                echo $path
                jre_found="true"
                fi
                elif [[ $major -gt 7 && $major -lt 11 ]]; then
                echo $path
                jre_found="true"
                fi
                done)

                # execute our jar file
                $jre_path/bin/java -jar "$DIR"/myApp.jar


                And now everything should be working from double click on myApplication.app.






                share|improve this answer














                Okay, looks like I found some crooked way to do this all.




                Windows solution:




                To bundle on Windows it's easy to use launch4j (windows only). It's free and there is no problem to create .exe with no Jre bundled.




                MacOS solution:




                For MacOS it's a bit harder:





                1. Create myApplication.app folder and design it's structure



                  enter image description here



                2. Write launcher bash script:
                  In my case I should detect which versions of Jre installed and choose any between java 1.8 and 10



                I don't know bash script language and I believe I write it unoptimized way. I would be happy if anyone correct me. Anyway it works the way as I wanted:




                #!/bin/sh

                # set the working directory
                DIR=$(cd "$(dirname "$0")"; pwd)

                # extract first fit java version installed
                jre_path=$(/usr/libexec/java_home -V 2>&1 |
                while IFS= read -r line
                do
                if [[ "$jre_found" == "true" ]]; then
                break
                fi
                version=$(echo $line | cut -d ' ' -f 1|sed 's/^ *//;s/ *$//' | cut -d ' ' -f 1 | sed 's/^ *//;s/ *$//')
                major=$(echo $version | cut -d. -f1)
                minor=$(echo $version | cut -d. -f2)
                array=(${line// /})
                array_size=${#array[@]}
                let "last_index=array_size-1"
                path=${array[ $last_index ]}

                if [[ $major == 1 ]]; then
                if [[ $minor -gt 7 && $minor -lt 11 ]]; then
                echo $path
                jre_found="true"
                fi
                elif [[ $major -gt 7 && $major -lt 11 ]]; then
                echo $path
                jre_found="true"
                fi
                done)

                # execute our jar file
                $jre_path/bin/java -jar "$DIR"/myApp.jar


                And now everything should be working from double click on myApplication.app.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 12 at 0:44

























                answered Nov 11 at 5:15









                Iga

                335




                335






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242661%2fpackaging-jar-file-for-mac-and-windows-without-jre-bundled%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini