Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Perhaps silly, but is it possible ...

Reply
Thread Tools

Perhaps silly, but is it possible ...

 
 
D. Alvarado
Guest
Posts: n/a
 
      05-26-2004
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
 
Reply With Quote
 
 
 
 
Stefan Wischnewski
Guest
Posts: n/a
 
      05-26-2004
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
 
Reply With Quote
 
 
 
 
John Davison
Guest
Posts: n/a
 
      05-26-2004
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
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      05-27-2004
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.
 
Reply With Quote
 
John Davison
Guest
Posts: n/a
 
      05-27-2004
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perhaps 20 years to late...but Diplom Kaufmann Knut Computer Support 0 09-05-2007 06:23 PM
Wrong forum perhaps but.. Bob The ASP Builder ASP General 1 04-08-2005 10:20 PM
Perhaps a newbie question... Klaus Kleiner VHDL 8 12-23-2003 05:30 PM
Perhaps a silly question, but... Writer1194 Computer Information 12 11-17-2003 05:52 PM
General Question (Trivia perhaps; but not trivial) HELP Please to-X-ic Computer Support 9 07-07-2003 01:06 AM



Advertisments