About executing class files....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    About executing class files....

    I have a class file that instantiates an object from a jar file
    or simply a class file inside the jar file is used as part of the simple program....

    When we use the the jar file in JSP, we simply put the complete filepath of the class files inside the manifest file(Name:) an enable the Java-Bean setting( set to true) then solved....(read y to use)

    What comes to mind is, im taking the short road, without an experience of running a class file that accessing another classfile(which is inside the jar file)...( Running a unjarred stand-alone application that uses another classfile inside the jar)

    i know how to compile it, javac -cp jarname.jar test.java

    but, i don't know how to execute it.....

    The jar file already been set-up, the index.list and the Name set to common...
    Which i found on a tutorial on the net....

    But, in my case, i've got nothing on the web.....

    Please let me know experts what is the pattern for executing such classfile like this scenario...... or a url that directly teach me how to deal with it....

    Waiting,
    sukatoa.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    I don't understand your question. What do you mean by 'that instantiates an
    object from a jar file'? A .jar file simply contains classes and other resources.

    kind regards,

    Jos

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Originally posted by JosAH
      I don't understand your question. What do you mean by 'that instantiates an
      object from a jar file'? A .jar file simply contains classes and other resources.

      kind regards,

      Jos
      Apologize!!!! :(

      Actually, im on the experiment now,

      I have created an API for my JSP project.....
      Which is jarred and no problem about that.....

      But i have a problem when im gonna use that on a stand-along program

      What i really don't know is the following:

      suppose i have a class file named SQLDriver that was jarred....(MyJa r.jar)
      and i have a class file(not jarred) named SQLDriverTest

      im going to use that SQLDriver class that was jarred from my SQLDriverTest

      javac -classpath MyJar.jar SQLDruverTest,j ava
      successfully compiled

      The problem is, i don't know how to execute the SQLDriverTest

      Can you teach me how to do it Jos?
      This is really an urgent, i need to distribute this to my groupmates as soon as possible, because i have created a stand-alone application that updates the database every 10 seconds and they must use that to be able test what they have done in their part.

      The stand-alone app will do the following:

      Delete those expired reservations
      Move those guests that suspectedly a criminal/terrorists
      Do Admin's priviledge
      Setting-up a database schema, its table and the columns

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        The JVM doesn't care where those classes come from: either from their own
        file or read from a .jar file or whatever; that is the concern of the ClassLoader.
        The SystemClassLoad er (the one you use by default) uses a 'classpath' variable
        for that purpose. That variable is a list of directories and/or .jar files. If that
        ClassLoader needs to load a file it checks the classpath and searches all those
        directories and/or mentioned .jar files for the wanted class.

        If, e.g. you store your .class files in directory /foo and your myJar.jar file in a
        directory /bar you should use a command line like this:

        [code=java]
        java -cp=/foo;/bar/myJar.jar MyClass
        [/code]

        The class MyClass can be stored in that .jar or in directory /foo; it doesn't matter
        and the ClassLoader will look in that directory or .jar file for all the classes it
        needs to load.

        kind regards,

        Jos

        ps use a colon instead of a semicolon for the separator of the elements in the
        classpath variable if you're using Un*x.

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          i got an error here.....

          NoClassDefFound Error test

          test is the SQLDriverTest

          im compiling them on the same folder

          java -cp DMA_OpenSource_ API.jar test
          is that correct?

          or should i put them in a sub folder? like what you've suggested?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            No that is not correct because you're not compiling anything there; you're trying
            to fire up the JVM.

            kind regards,

            Jos

            ps. also study this.

            Comment

            • sukatoa
              Contributor
              • Nov 2007
              • 539

              #7
              Originally posted by JosAH
              No that is not correct because you're not compiling anything there; you're trying
              to fire up the JVM.

              kind regards,

              Jos
              I forgot to mention,

              It was already compiled using

              javac -cp DMA_OpenSource_ API.jar test.java


              and now, my latest reply doesn't seem to work....
              java -cp DMA_OpenSource_ API.jar test

              Error: NoClassDefFound Error: test

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by sukatoa
                I forgot to mention,

                It was already compiled using

                javac -cp DMA_OpenSource_ API.jar test.java


                and now, my latest reply doesn't seem to work....
                java -cp DMA_OpenSource_ API.jar test
                Hrm; is that test class a class in a package? Also be sure to include the current
                directory in your classpath like so:

                [code=java]
                java -cp DMA_OpenSource_ API.jar;. test
                [/code]

                kind regards,

                Jos

                ps. see the ps I added a bit later in my previous reply.

                Comment

                • sukatoa
                  Contributor
                  • Nov 2007
                  • 539

                  #9
                  Originally posted by JosAH
                  Hrm; is that test class a class in a package? Also be sure to include the current
                  directory in your classpath like so:

                  [code=java]
                  java -cp DMA_OpenSource_ API.jar;. test
                  [/code]

                  kind regards,

                  Jos

                  ps. see the ps I added a bit later in my previous reply.

                  hahahahahahhhh. ...... You're a God like Jos,

                  You got it, the dot ( . ) is i really don't know if they are on the same folder and im also on that folder using cmd......

                  Thank you very much Jos...... :)

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by sukatoa
                    hahahahahahhhh. ...... You're a God like Jos,
                    I know ;-)

                    Originally posted by sukatoa
                    You got it, the dot ( . ) is i really don't know if they are on the same folder and im also on that folder using cmd......

                    Thank you very much Jos...... :)
                    You're welcome of course but also read that link I supplied in reply #6 so that
                    you'll understand completely what that classpath is all about.

                    kind regards,

                    Jos

                    Comment

                    • sukatoa
                      Contributor
                      • Nov 2007
                      • 539

                      #11
                      Originally posted by JosAH
                      You're welcome of course but also read that link I supplied in reply #6 so that
                      you'll understand completely what that classpath is all about.

                      kind regards,

                      Jos
                      Yes, i will........... ............... :)

                      Comment

                      • sukatoa
                        Contributor
                        • Nov 2007
                        • 539

                        #12
                        I got new problem here......

                        I've jarred my test.class, added Class-Path: DMA_OpenSouce_A PI.jar(with the com folder added)
                        successfully run.....

                        Now, I would like to have that mysql-connector-java-5.0.8-bin.jar independently.. ...
                        Instead of adding the com folder(from mysql-connector-java-5.0.8-bin.jar) into my DMA_OpenSouce_A PI.jar,

                        Now, i don't know how to add another path here.....

                        I've made: Class-Path: DMA_OpenSouce_A PI.jar; mysql-connector-java-5.0.8-bin.jar(newline )

                        to the manifest(From my test.jar), but it doesn't work...... How can i reproduce that one?
                        Jos, what can you recommend about this?

                        waiting,
                        sukatoa

                        PostScript: The test.jar, DMA_OpenSouce_A PI.jar and the mysql-connector-java-5.0.8-bin.jar are on the same folder.....

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by sukatoa
                          I got new problem here......

                          I've jarred my test.class, added Class-Path: DMA_OpenSouce_A PI.jar(with the com folder added)
                          successfully run.....

                          Now, I would like to have that mysql-connector-java-5.0.8-bin.jar independently.. ...
                          Instead of adding the com folder(from mysql-connector-java-5.0.8-bin.jar) into my DMA_OpenSouce_A PI.jar,

                          Now, i don't know how to add another path here.....

                          I've made: Class-Path: DMA_OpenSouce_A PI.jar; mysql-connector-java-5.0.8-bin.jar(newline )

                          to the manifest(From my test.jar), but it doesn't work...... How can i reproduce that one?
                          Jos, what can you recommend about this?

                          waiting,
                          sukatoa

                          PostScript: The test.jar, DMA_OpenSouce_A PI.jar and the mysql-connector-java-5.0.8-bin.jar are on the same folder.....
                          Read here.
                          not Jos

                          Comment

                          • sukatoa
                            Contributor
                            • Nov 2007
                            • 539

                            #14
                            Ok, i got it, here is the link......

                            No semi-colon anymore......

                            PS: Thanks for the url r035198x, I think google doesn't know what i really like to look for..... :(

                            Comment

                            • sukatoa
                              Contributor
                              • Nov 2007
                              • 539

                              #15
                              Originally posted by sukatoa
                              Ok, i got it, here is the link......

                              No semi-colon anymore......

                              PS: Thanks for the url r035198x, I think google doesn't know what i really like to look for..... :(
                              Ok, here is a new problem again,

                              My DMA_OpenSouce_A PI.jar wants to access a class from mysql-connector-java-5.0.8-bin.jar.... not my test.jar....

                              So, in common-sense, i should not add the classpath for the mysql-connector-java-5.0.8-bin.jar in my test.jar, instead, i should add it from the manifest of my DMA_OpenSource_ API.jar......

                              But i don't know how....

                              Here is the content of DMA_OpenSouce_A PI.jar

                              MANIFEST.MF:
                              Code:
                              Manifest-Version: 1.0
                              Specification-Title: DMA OpenSourceā„¢ API Specification
                              Created-By: 1.0 (DMA OpenSourceā„¢ Inc)
                              Implementation-Title: Java Runtime Environment
                              
                              Name: common
                              INDEX.LIST
                              Code:
                              JarIndex-Version: 1.0
                              
                              DMA_OpenSource_API.jar
                              dma
                              dma/constants
                              dma/data
                              dma/data/secure
                              dma/db
                              dma/files
                              dma/printer
                              dma/system
                              dma/time
                              dma/utility
                              dma/utility/converter
                              Now, i don't know where to put such Header "Class-Path", since all the tutorials i saw on the web is all about dealing such scenario with the main-class

                              Please do correct me if i forgot something here....

                              Waiting again,
                              sukatoa

                              Comment

                              Working...