Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How does one locate the java executable and various JAR files in the classpath?

Reply
Thread Tools

How does one locate the java executable and various JAR files in the classpath?

 
 
DM McGowan II
Guest
Posts: n/a
 
      12-10-2005
Oliver Wong wrote:

>
> [1]: I want the JAR file, and not any particular class within the JAR,
> because I want to construct a string to pass to Runtime.exec(). Something
> like Runtime.exec("java -jar /path/to/jar/myMysteriousJARFile.jar", null,
> myDesiredWorkingDirectory); I was hoping to take the URL from the
> classloader, assuming it points to the local filesystem, and then convert
> it to an absolute path using the File class.


Is it possible to write a class loader then load the JAR rather than take
the performance hit of running a separate Java process? Just curious.

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      12-10-2005
Oliver Wong wrote:

> I have a JAR file which does some useful stuff, including generating
> some files into the "current directory". That is, it creates new File
> objects using relative paths, and so these files appear relative to the
> directory from which the JAR was invoked.


[I see that you've already found a workaround, and anyway this is just an
observation.]

IMO, any API that /depends/ on the idea of a "current directory" is broken in
this day and age. There's nothing wrong with allowing relative filenames to be
specified as inputs to the API, but it seems foolish to create files in
locations that the user (programmer) can't control.

Perhaps you can encourage the authors of your JAR to un-break the API ?

-- chris



 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      12-10-2005
On Sat, 10 Dec 2005 14:15:31 -0000, "Chris Uppal"
<(E-Mail Removed)-THIS.org> wrote, quoted or indirectly
quoted someone who said :

>IMO, any API that /depends/ on the idea of a "current directory" is broken in
>this day and age. There's nothing wrong with allowing relative filenames to be
>specified as inputs to the API, but it seems foolish to create files in
>locations that the user (programmer) can't control.


It makes not much sense in a multithread program. Each thread would
need its own version of the CWD.

Your problem really is Windows There are so many ways to invoke a
program it is easy to get confused what CWD you are giving it.

Some experiments are in order . Just display the CWD first thing on
the console, and experiment till you feel confident you have it under
control.

See http://mindprod.com/jgloss/file.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
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
Running an Executable Before Executable JAR Jason Cavett Java 8 05-16-2007 07:14 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
Re: Can I make .class files run like executable .jar files on a Windows platform? kamal Java 0 03-10-2005 10:42 AM
Can I make .class files run like executable .jar files on a Windows platform? phillipedison1891@yahoo.com Java 3 03-09-2005 10:44 PM
Classpath problem: javap is able to locate one class in a jar but not the other. Chandresh Prakash Java 1 12-05-2003 12:43 PM



Advertisments