Results 1 to 5 of 5
  1. #1
    JimmyD is offline Member
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    44
    Rep Power
    0

    Default ClassPath max length

    Hi,

    I encounter a problem dealing with class path today. It appears to me that windows only allows a certain length of classpath.

    Let's me explain a bit how i reached the maximum length of class path.
    I did not have any training on good practices of java development. I've been using a naive approach: for every library package I download from internet (e.g. skype API, twitter API), I append the .jar file to the class path. For the projects I developed myself, I put up the project folder in the class path. (that looks sth like C:\user\project1). I have not learned how to properly package codes and use packages.

    As a result, my class path length right now is 2036, and I notice I can only append up to a length of 2048.

    I tried to do some googling, and the most relavent post I found is the following:
    How do I extend the maximum file path size in Windows 7? - Super User

    Am I doing something wrong here? Is there a solution to my problem?

    Thanks in advance for anyone who offers suggestions and insights!!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: ClassPath max length

    My advice would be to *not* use a CLASSPATH environment variable. (I'm guessing that it is the environment variable that is causing the problem.)

    The Java tools - javac.exe, java.exe, jar.exe, ... - all allow you to specify the classpath when you use the tool:

    Java Code:
    javac -cp c:\user\project1;c:\jars\whatever.jar *.java
    Using this approach you would specify a classpath that only includes the resources you actually want to use. This is also more flexible if you ever have multiple versions of jar files and what to compile your code using some particular version.

    The javac documentation includes a note on Command Line Argument Files that explains how "to create javac commands of any length on any operating system".

  3. #3
    JimmyD is offline Member
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    44
    Rep Power
    0

    Default Re: ClassPath max length

    Thank pbrockway! Right now I am trying to package all my own projects, so that I only need to include the parent dir, and all my sub packages will be referenced by doing
    import project1.*;
    import project2.util.*;

    etc, that might help me to save some space.

    But ya, I always see tutorials showing how to run the client by including class path on command line. whenever I read that, I always think "why bother to type that long line when I can include it in class path var and do it in a simpler way." I guess right now I understand the reason.

    One curious question though, is there a max length on the classpath environmental var for windows?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: ClassPath max length

    As far as your projects are concerned if the project1, project2, etc directories are all in the same place then it makes it easy to set the classpath.

    I should have mentioned that Setting the class path is worth a read. It points out that if you have a whole bunch of thirdparty jars in a single directory you can put the whole lot on the classpath using a * wildcard. (You still run into the version problem though.)

    I would put money on Windows putting a limit on the length of a CLASSPATH (or other) variable. But I don't know for sure - you could easily check by making one larger and larger until something breaks.

  5. #5
    JimmyD is offline Member
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    44
    Rep Power
    0

    Default Re: ClassPath max length

    Thanks again for the reference. For the last part of your comment, I in fact have already mentioned that I observe a "2048" char limit on the classpath variable allowed by windows.

Similar Threads

  1. you cant do var.length - 1?
    By javanubby in forum New To Java
    Replies: 3
    Last Post: 03-15-2012, 10:28 PM
  2. Difference between length() and length
    By mitra in forum New To Java
    Replies: 7
    Last Post: 07-28-2011, 01:46 AM
  3. Replies: 1
    Last Post: 05-03-2011, 03:28 AM
  4. help with length
    By ama91 in forum New To Java
    Replies: 15
    Last Post: 02-21-2011, 02:44 AM
  5. String.length?
    By rizowski in forum New To Java
    Replies: 7
    Last Post: 11-20-2010, 06:33 PM

Posting Permissions

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