问题
I've made applet, Here's files from its jar.

In my classes I've call ffmpeg.exe
, and I have all privileges like self-signed applet and make call via Access Controller. So I've getting error in program, It's can't be find *my ffmpeg lib*
.
This should be very easy Q: where should I place my ffmpeg.exe file ?
And I've get exception as:
Cannot run program "ffmpeg": CreateProcess error=2, ?? ??? ??? ????? ????
The code are following as:
public class DtpVideoApplet extends Applet
{
public String startRecording() throws IOException
{
try
{
return(String) AccessController.doPrivileged(new PrivilegedAction<String>()
{
public String run()
{
try
{
Runtime.getRuntime()
.exec("ffmpeg -y -f dshow -i video=\"screen-capture-recorder\" output.flv");
return "Entered";
}
catch (Exception e)
{
// TODO Auto-generated catch block
return e.getMessage();
}
}
});
}
catch (Exception e)
{
return e.getMessage();
}
}
}
回答1:
I never run an .exe from an applet, however I'm load some .dlls from an applet resource, to do this first I copy my applet resources to temp path and then I load it from this path. The dlls are located inside the jar how is showed below:

loadLib method copies .dlls to disc and then load it, this method receive as parameters the directory and the name of the file (in my case the method call is loadLib("/sun/security/mscapi/","sunmscapi_x32.dll"); )
public static void loadLib(String libraryPath, String libraryName) throws IOException, InterruptedException{
System.out.println(libraryPath + "---------------------");
URL inputStreamLibURL = AddSunMSCAPIProvider.class.getResource(libraryPath);
if(inputStreamLibURL==null){
throw new IOException("Resource not found: " + libraryPath);
}
String tempPath = System.getProperty("java.io.tmpdir", NOT_FOUND);
if(tempPath.equals(NOT_FOUND)){
throw new IOException("Temporary File not found");
}
File tempDir = new File(tempPath);
//first try to overwrite the default file
File defaultFile = new File(tempPath, libraryName);
boolean useDefaultFile = false;
if(defaultFile.exists()){
try{
useDefaultFile = defaultFile.delete();
//return false if the library cannot be deleted (locked)
}catch(Exception e){
e.printStackTrace();
useDefaultFile = false;
}
}else{
useDefaultFile = true;
}
File tempFile;
if(useDefaultFile){
tempFile = defaultFile;
}else{
tempFile = File.createTempFile(libraryName, "", tempDir);
}
copy(inputStreamLibURL.openStream() ,tempFile, 0);
Runtime.getRuntime().load(tempFile.getAbsolutePath());
}
/**
* File copy
* @param src
* @param dest
* @param bufferSize
* @throws IOException
*/
private static void copy(InputStream src, File dest, int bufferSize) throws IOException{
if(bufferSize<=0){
bufferSize = 2000; //default bytebuffer
}
InputStream is = src;
OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
byte[] buffer = new byte[bufferSize];
int c;
while((c = is.read(buffer))!= -1){
os.write(buffer, 0, c);
}
is.close();
os.close();
return;
}
Of course in order to do this operations, the applet must be correct signed and necessary MANIFEST permissions added.
Hope this helps,
来源:https://stackoverflow.com/questions/21928936/applets-jar-cant-find-resource