How to open a bundled executable in the project?

1

I'm running a program as follows:

Runtime.getRuntime().exec("C:\meuprograma.exe");

In which it works normally. But I would like to package the files (the executable and some more) inside my project so the user does not have to be manipulating the files. What's more, the file is important only at runtime, so there's no need for me to create a directory to "install" the required files (unless that's the only solution, of course). I've created a structure similar to this:

src
 |__ br.foo.files
 |__ br.foo.main

Assuming my class that will call the executable is inside the main package, how do I execute a file inside the files package? I tried:

Runtime.getRuntime().exec("files/meuprograma.exe");
Runtime.getRuntime().exec("./files/meuprograma.exe");
Runtime.getRuntime().exec("/files/meuprograma.exe");

In which all generated the following exception:

  

Exception in thread "main" java.io.IOException: Can not run program   "files / meuprograma.exe": CreateProcess error = 2, The system can not   find the specified file

    
asked by anonymous 23.01.2015 / 17:15

1 answer

1

Use:

File home = new File(System.getProperty("user.dir"));
File file2 = new File(home, "files/meuprograma.exe");
Runtime.getRuntime().exec(file2.getPath());

Documentation .

You can do this by concatenating strings without creating the actual path , but this is the right way.

    
23.01.2015 / 17:25