12 Replies Latest reply: Feb 4, 2013 10:18 PM by EJP RSS

    Creating a jar using api

    Gen.Java
      Hi all,

      Using JDK 6, I need to use jar api to create a jar file for a simple JavaFX application. I used to use jar api to create jar files for Java applications, but now I need to do the same for JavaFx applications. The problem is referencing JavaFX's "jfxrt.jar". I cannot put the directory where "jfxrt.jar" is on the Class-Path because the directory name includes spaces, and entry names cannot have spaces, ex. "c:\Program File\...". What can I do ?

      Thank you
        • 1. Re: Creating a jar using api
          Narayan
          Hi gen,

          I don't know what the jar api mean. Do you mean this api ? http://docs.oracle.com/javase/1.4.2/docs/api/java/util/jar/package-summary.html

          Or you mean to make jar file using command line?

          If you are using command line then either you can set Class-Path at Manifest.mf or you can run the jar file using Classpath


          Using Manifest.mf
          Manifest-Version: 1.0
          Class-Path: . file:///C:/Program%20Files%20(x86)/Java/jdk1.7.0_09/jre/lib/jfxrt.jar
          Main-Class: test.HelloWorld
          For more info about manifest goto here : http://docs.oracle.com/javase/tutorial/deployment/jar/defman.html

          Using -cp option while executing Jar from commandline
          Syntax: java -cp "current path;path of your jfxrt" -jar JarfileName.jar
          Example: java -cp ".;C:\Program Files (x86)\Java\jdk1.7.0_09\jre\lib\jfxrt.jar" Test.jar
          Using either of one of above approach can execute the jar file containing javafx class

          Thanks
          Narayan
          • 2. Re: Creating a jar using api
            Gen.Java
            Hi Narayan,

            Thank you so much.
            Narayan wrote:
            I don't know what the jar api mean. Do you mean this api ? http://docs.oracle.com/javase/1.4.2/docs/api/java/util/jar/package-summary.html
            Yes

            After programming with Java for years, I discovered that I misunderstood two facts:

            1. Class-Path entries cannot be absolute. Now I can use obsulute paths by prefixing them with "file:///C:/"
            2. Class-Path entries cannot include spaces. Now I can use spaces by using "%20" to make a space.

            You proved that I was wrong about those two issues. Thank you.

            I noticed that you used jdk 7 in your example. why do we still have to put "jfxrt.jar" on the classpath, isn't it part of JDk 7 now?

            Thank you again
            • 3. Re: Creating a jar using api
              Narayan
              Hi gen,

              You are welcome !!

              Although it is the part of jdk 7 , I guess it is not a part of the core jdk.
              Also to prove that things of your problem I've used the jdk 7 as an example.
              In my computer I have jdk 6 and 7. I use mostlly jdk 6 for making the Java application and 7 for JFX application.
              I used to do packing of jar myself while I was new to Netbeans. But now Netbeans is there for me to make these stuffs. ;)

              Thanks
              Narayan

              Edited by: Narayan on Jan 23, 2013 9:04 PM
              • 4. Re: Creating a jar using api
                Gen.Java
                Narayan wrote:
                In my computer I have jdk 6 and 7. I use mostlly jdk 6 for making the Java application and 6 for JFX application.
                Why do you use JDK 7 (and not 6) for JFX applications (I assume that there is a typo here) ?
                • 5. Re: Creating a jar using api
                  Narayan
                  Hi gen,

                  Nice question :) and thanks for gettting correct vision of my typo.

                  I like the new technology of JDK 7 like Diamond features and many more.Also i think jdk 7 has more performance than in the jdk6. Client prefers the latest technology and fast performance as well. I always update my Netbeans to make it load faster and the new version of Net beans supports the automatic JavaFX detection for JDK7 and i feel just easy to use jdk 7 while developing.

                  Although JDK6 is not bad , all the Java-based software I build under jdk 6 for fixing the compatibility issue. I think JDK6 is one of the long lasting stable and best version as per my experience on java. But when it comes of JavaFX it recommends at least jdk 7 as it comes with bundled(No extra installation) and with many good features and performance.


                  Thanks
                  Narayan

                  Edited by: Narayan on Jan 23, 2013 9:04 PM
                  • 6. Re: Creating a jar using api
                    jsmith
                    Why do you use JDK 7 (and not 6) for JFX applications?
                    In addition to Narayan's reasons:
                    The last publicly available release of Oracle JDK 6 is to be released in February, 2013. This means that after 19 February 2013, all new security updates, patches and fixes for Java SE 6 and Java SE 5 will only be available through My Oracle Support and will thus require a commercial license with Oracle.
                    https://blogs.oracle.com/java/entry/end_of_public_updates_for

                    For client applications on a relatively immature platform like JavaFX which is undergoing lots of active development and changes, that's not good because it means that you stop getting security updates, new features and bug fixes. Additionally JavaFX + JDK6 only works on Windows machines, not on Linux or OS X, so the potential reach of your applications is artificially limited. Further, some functionality such as self-contained application packaging is only available for jdk7+.
                    • 7. Re: Creating a jar using api
                      Gen.Java
                      Thank you Narayan and jsmith for your replies. Sorry for the late response, I was away for a while
                      • 8. Re: Creating a jar using api
                        EJP
                        1. Class-Path entries cannot be absolute.
                        Correct. That's what the specification says.
                        Now I can use obsulute paths by prefixing them with "file:///C:/"
                        If that really works, it is a bug and not to be relied on. Stick to what it says in the specification.
                        2. Class-Path entries cannot include spaces.
                        Correct. Class-path entries are URLs, and URLs cannot contain spaces.
                        Now I can use spaces by using "%20" to make a space.
                        Correct. That is the defined encoding for space in a URL.
                        You proved that I was wrong about those two issues. Thank you.
                        No he didn't. He found what appears to be a bug. Don't rely on it being there next release.

                        More probably, you don't have to put that JAR file on the Class-path at all because of where it is, so the absolute entry in the Class-path doesn't work but it doesn't have to.
                        • 9. Re: Creating a jar using api
                          Gen.Java
                          EJP wrote:
                          More probably, you don't have to put that JAR file on the Class-path at all because of where it is, so the absolute entry in the Class-path doesn't work but it doesn't have to.
                          Hi EJP,

                          You mean I can run a JavaFX application's jar without putting that "jfxrt.jar" on the Class-Path ?
                          • 10. Re: Creating a jar using api
                            EJP
                            Do you know what 'more probably' means?

                            You could always try it.
                            • 11. Re: Creating a jar using api
                              Narayan
                              Hi GenJava,
                              If you are using jdk7/jre7 u7 or greater then you don't need to add the jfxrt.jar at classpath because the jfxrt.jar is already bundled inside the jre package.

                              But I guess you need to change some stuffs of your manifest.mf (Although I have not tested yet but you can try with these)
                              Manifest-Version: 1.0
                              JavaFX-Version: 2.2
                              JavaFX-Application-Class: test.HelloWorld
                              Main-Class: com/javafx/main/Main  /*this is always same non changable*/
                              Thanks
                              Narayan
                              • 12. Re: Creating a jar using api
                                EJP
                                That isn't any better than your previous guess. It should be:
                                Main-Class: com.javafx.main.Main
                                Re your previous guess, the JAR File Specification says this: "Class-Path: The value of this attribute specifies the *+relative+* [my emphasis] URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path."