CLASSPATH variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stmfc
    New Member
    • May 2007
    • 65

    CLASSPATH variable

    i dont have any environment variable CLASSPATH on my PC,
    but i can write some java programs via eclipse and run them.
    what is the story? do not i need to have CLASSPATH variable in my environment?
  • mattmao
    New Member
    • Aug 2007
    • 121

    #2
    Eclipse is an IDE, so it automatically creates a proper CLASSPATH for your Java classes behind the scenes. You don't have to worry about this.

    But if you want to manually specify the CLASSPATH, google for the tutorials. This is fundamental so you would find hundreds of pages about it:)

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by stmfc
      do not i need to have CLASSPATH variable in my environment?
      Not only don't you need it, you shouldn't want it either. Either pass the classpath
      value on the command line when you start the jvm or let your IDE deal with those
      nasty little details.

      kind regards,

      Jos

      Comment

      • stmfc
        New Member
        • May 2007
        • 65

        #4
        Originally posted by JosAH
        Not only don't you need it, you shouldn't want it either. Either pass the classpath
        value on the command line when you start the jvm or let your IDE deal with those
        nasty little details.

        kind regards,

        Jos

        in a SCJD exam tutorial i see a warning like this:
        "When using an IDE (or not, but there’s more of a danger when using an IDE) you can end up being sheltered and protected from things like classpath issues, which allow your program to run fine on your machine and then blow up (OK, just fail to run) at runtime on another system."

        thats why i am confused, and why i want to learn how to set CLASSPATH variable, or at least learn how to write portable programs without worrying about CLASSPATH setting.

        thanks in advance...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          When you package your application in one or more .jar files you normally set
          the classpath values in the .jar manifest file but you never want that variable to
          be set in your environment.

          For unpackaged applications you can pass that classpath variable on the
          command line when you start your virtual machine.

          kind regards,

          Jos

          Comment

          • stmfc
            New Member
            • May 2007
            • 65

            #6
            Originally posted by JosAH
            When you package your application in one or more .jar files you normally set
            the classpath values in the .jar manifest file but you never want that variable to
            be set in your environment.

            For unpackaged applications you can pass that classpath variable on the
            command line when you start your virtual machine.

            kind regards,

            Jos



            Hi JosAH,
            unfortunately i am still unclear with this CLASSPATH issue.
            in a tutorial explaining Jakarta's POI project i saw an explanation as follows:

            Installing HSSF
            Go to the Jakarta.apache. org/poi site and download the latest binary for the POI project. Install it anywhere in your system. POI uses Jakarta's commons-logging package. The download includes with the Jakarta-commons.jar file and you must have that path in your classpath to run POI based applications.

            i am using eclipse so what should i do for CLASSPATH?
            i am not starting my applications via command-line so i cannot pass the classpath variable, and i am not packing them into a jar file for now.

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              Originally posted by stmfc
              Hi JosAH,
              unfortunately i am still unclear with this CLASSPATH issue.
              in a tutorial explaining Jakarta's POI project i saw an explanation as follows:

              Installing HSSF
              Go to the Jakarta.apache. org/poi site and download the latest binary for the POI project. Install it anywhere in your system. POI uses Jakarta's commons-logging package. The download includes with the Jakarta-commons.jar file and you must have that path in your classpath to run POI based applications.

              i am using eclipse so what should i do for CLASSPATH?
              i am not starting my applications via command-line so i cannot pass the classpath variable, and i am not packing them into a jar file for now.
              You're using eclipse, right? Do the following:
              1. Open your project in eclipse
              2. Right click on your package in the package explorer
              3. Chose "Properties "
              4. Chose "Java Build Path"
              5. Click on "Add External JARs"
              6. Choose the JAR, you want to add (jakarta-commons.jar)
              7. Close the Properties Window
              That should make Eclipse add that JAR to your classpath.

              Greetings,
              Nepomuk

              Comment

              • stmfc
                New Member
                • May 2007
                • 65

                #8
                now everything is more clear.
                josah, mattmao and nepomuk thank you very much.

                Comment

                Working...