Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Java classpath

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java classpath

    Java newbie here......

    I'm on a winxp pc and got java installed in C:\j2sdk1.4.2_06

    I've set the PATH environment variable to point to C:\j2sdk1.4.2_06\bin

    I'm getting an errormessage all the time when trying to run my classes:
    Exception in thread "main" java.lang.NoClassDefFoundError: MyClass

    I suspect this is coming from not setting the CLASSPATH.

    Where should the CLASSPATH point to??

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are running from the command prompt then you can use the -cp or -classpath parameters in the command line to specify the classpath. Use "java -?" to find out all the options you have.

    shmoove

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shmoove
    If you are running from the command prompt then you can use the -cp or -classpath parameters in the command line to specify the classpath. Use "java -?" to find out all the options you have.

    shmoove
    If I have no classpath at all everything works fine. But since I've installed Tomcat I need to have a classpath variable.

    I can run my programs from anywhere on the disk using: java -cp "." MyClass
    ...and it works fine. But it's very bothersome.

    How can i avoid using -cp ??

    I was into java about 4 years ago, and never had a problem with this. What've changed?

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've had problems setting up with my IDE using the Java SDK so instead i used the JDK and i had no problems. The difference is that they renamed it with the newer version. Old versions = Java SDK, new versions = JDK. It's on the site, i think it's 1.5.0. Anyway, try JDK out instead and see if it fixes the problem.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Quote Originally Posted by Pompiuses
    I can run my programs from anywhere on the disk using: java -cp "." MyClass
    ...and it works fine. But it's very bothersome.
    that is because with the -cp option, you set the current directoryas the classpath.
    Quote Originally Posted by Pompiuses
    How can i avoid using -cp ??
    By setting the classpath in your environment variables. add (or change) the CLASSPATH environment variable, with all the folders in it from where you want to use your classfiles. You can also add folders to the classpath in a cmdfile with the next command:
    set %CLASSPATH%=%CLASSPATH%;yourpathname

    Then it will be added for the current commandwindow
    I am the luckiest man in the world


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •