Perhaps silly, but is it possible ...

Discussion in 'Java' started by D. Alvarado, May 26, 2004.

  1. D. Alvarado

    D. Alvarado Guest

    to load a file into the classpath AFTER you have started your Java
    program? That is, I know the path to a file, but that file does not
    appear in the CLASSPATH enviornment variable or in any -CLASSPATH
    directive passed to the java invocation. Perhaps a bit silly, but I
    have no control over the environment or runtime setting s, which is
    why I'm seeking a back door.

    If the answer is yes, how could this be done?

    Thanks in advance, - Dave
     
    D. Alvarado, May 26, 2004
    #1
    1. Advertising

  2. D. Alvarado wrote:
    > to load a file into the classpath AFTER you have started your Java
    > program? That is, I know the path to a file, but that file does not
    > appear in the CLASSPATH enviornment variable or in any -CLASSPATH
    > directive passed to the java invocation. Perhaps a bit silly, but I
    > have no control over the environment or runtime setting s, which is
    > why I'm seeking a back door.
    >
    > If the answer is yes, how could this be done?
    >
    > Thanks in advance, - Dave

    Not silly at all. Take a look at the URLClassLoader.

    Stefan
     
    Stefan Wischnewski, May 26, 2004
    #2
    1. Advertising

  3. D. Alvarado

    John Davison Guest

    D. Alvarado wrote:

    > to load a file into the classpath AFTER you have started your Java
    > program? That is, I know the path to a file, but that file does not
    > appear in the CLASSPATH enviornment variable or in any -CLASSPATH
    > directive passed to the java invocation. Perhaps a bit silly, but I
    > have no control over the environment or runtime setting s, which is
    > why I'm seeking a back door.
    >
    > If the answer is yes, how could this be done?
    >
    > Thanks in advance, - Dave


    You don't load files into the classpath. That doesn't make sense. All
    the classpath does (AFAIK) is supply the JVM with directories to search
    through for Java .class files.

    If you need to open a file, simply provide the full path from root, or a
    relative path. The classpath has nothing to do with this.

    File f = new File("/some/path/to/your/file");

    - john
     
    John Davison, May 26, 2004
    #3
  4. John Davison wrote:
    > You don't load files into the classpath. That doesn't make sense. All
    > the classpath does (AFAIK) is supply the JVM with directories to search
    > through for Java .class files.


    No, you can also use it to load all kinds of files via the "resource" methods
    in the Class and ClassLoader classes. This is in fact the preferred method
    because it allows the files to be packaged with the application and found
    regardless of the install location (end even within a JAR file).

    Of course, the advantages disappear when you first have to make a new
    ClassLoader via an absolute path anyway.
     
    Michael Borgwardt, May 27, 2004
    #4
  5. D. Alvarado

    John Davison Guest

    Michael Borgwardt wrote:

    > John Davison wrote:
    >
    >> You don't load files into the classpath. That doesn't make sense.
    >> All the classpath does (AFAIK) is supply the JVM with directories to
    >> search through for Java .class files.

    >
    >
    > No, you can also use it to load all kinds of files via the "resource"
    > methods
    > in the Class and ClassLoader classes. This is in fact the preferred method
    > because it allows the files to be packaged with the application and found
    > regardless of the install location (end even within a JAR file).
    >
    > Of course, the advantages disappear when you first have to make a new
    > ClassLoader via an absolute path anyway.


    You're right. I stand corrected.
     
    John Davison, May 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus Kleiner

    Perhaps a newbie question...

    Klaus Kleiner, Dec 22, 2003, in forum: VHDL
    Replies:
    8
    Views:
    870
    Steve Harrad
    Dec 23, 2003
  2. Stephajn Craig

    Perhaps an XML file might do this trick?

    Stephajn Craig, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    448
    Stephajn Craig
    Jun 26, 2003
  3. Homa
    Replies:
    7
    Views:
    452
    John Saunders
    Nov 16, 2003
  4. Rob Meade

    ASP.Net / AJAX - silly question perhaps

    Rob Meade, Jul 24, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    411
    Cowboy \(Gregory A. Beamer\)
    Jul 24, 2007
  5. Bob The ASP Builder

    Wrong forum perhaps but..

    Bob The ASP Builder, Apr 8, 2005, in forum: ASP General
    Replies:
    1
    Views:
    103
    David Morgan
    Apr 8, 2005
Loading...

Share This Page