this problem is already bugging me, so I was curious how your approaches should handle the following situation:
Imagine that I have two different eclipse projects in the same workspace as ProjectA and ProjectB. ProjectB contains the .exe file in its root, which is called from ProjectA as follows:
Process p = Runtime.getRuntime().exec( "../ProjectB/ProjectB.exe" );
The problem is that after deployment, the structure changes a bit: ProjectA is now .jar. Next to this bank is now a folder with ProjectB, which contains ProjectB with its .exe, .jars, and so on. Now the correct call should look like this:
Process p = Runtime.getRuntime().exec( "ProjectB/ProjectB.exe" );
Since I need these structures to stay as they are, and I don't want two different .exec calls in my application for each case, I tried several things to get around this situation:
1) Adding ProjectB as a ClassFolder to ProjectA and allowing ContextClassLoader, where to find ProjectB.exe as follows:
URL url= Thread.currentThread().getContextClassLoader().getResource( "ProjectB.exe" ); file = new File( url.toURI() ); Process p = Runtime.getRuntime().exec( file.getAbsolutePath() );
This solution worked fine until I tried to deploy my application to a network drive.
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI has an authority component at java.io.File.<init>(Unknown Source)
2) Since I am not allowed to create a network drive for each client, I tried to work around this problem and did the following:
URL url= Thread.currentThread().getContextClassLoader().getResource( "ProjectB.exe" ); File file = new File( url.getFile() ); Process p = Runtime.getRuntime().exec( file.getAbsolutePath() );
It seemed promising, but unfortunately, until my path was left without a dash ("), as this rating seemed to turn every dash into"% 20 ", which, apparently, does not look like runtimeexecutor Of course, I could replace every "% 20" with "" later, but that seems awkward to me.
Another requirement is that both applications must run in a different JVM, so I call the .exe file using Runtimeexecution. So my last question is: is there a way for ProjectB calls to be clean without any workarounds?