0

I understand this line of code runs .exe's based of a specific set location

Runtime.getRuntime().exec("C:/Users/Username/Desktop/JavaApp.exe").waitFor();

but I need it to run the application based off of the location of the class it is ran in

eebbesen
  • 5,070
  • 8
  • 48
  • 70
  • I believe [this](http://stackoverflow.com/questions/227486/find-where-java-class-is-loaded-from) is what you're looking for. – Zoltorn Feb 06 '14 at 03:03
  • It does show me where my class is even if it is moved but i need to be able to put it in the .exec; it doesn't work because it is an url not a string. – user3277831 Feb 06 '14 at 23:39
  • So I converted it to a String but how do I remove the file: part? It tries to run it like file:/C:/etc – user3277831 Feb 07 '14 at 00:10
  • 1
    [This answer](http://stackoverflow.com/a/227640/207421) is specifically what you're looking for. – user207421 Feb 07 '14 at 02:23

1 Answers1

0

I'm gonna go ahead and make an answer for this question.

I believe this is what you're looking for.


For your comment asking about removal of the 'file' part from your string

Assuming you have a string called path which contains: "file:/C:/Users/Jon/Test/foo/Test.class"

You can call path.substring(5), which will return a string containing the text "/C:/Users/Jon/Test/foo/Test.class". The int just represents the index you want to start at for your new string, so you can change that as you need.

Community
  • 1
  • 1
Zoltorn
  • 171
  • 1
  • 2
  • 10