2014-02-21 3 views
0

애플릿을 만들었습니다. 다음은 jar 파일입니다. 내 수업에서애플릿 jar cant find resource

enter image description here

나는했습니다 ffmpeg.exe를 호출하고 난 자체 서명 된 애플릿 같은 모든 권한을 가지고 액세스 컨트롤러를 통해 전화를 걸. 프로그램에서 오류가 발생했습니다. *my ffmpeg lib*을 찾을 수 없습니다.

매우 간단해야합니다. Q : ffmpeg.exe 파일은 어디에 두어야합니까?

그리고 나는이 GET 예외했습니다 :로

Cannot run program "ffmpeg": CreateProcess error=2, ?? ??? ??? ????? ???? 

코드는 다음과 같다 : 나는 애플릿에서 .EXE를 실행하지

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(); 
    } 
    } 
} 
+0

코드가 수행하는 (게시하는) 작업과 예외는 무엇입니까 (전체 스택 추적 게시 하시겠습니까?)? –

+0

귀하의 의견을 보내 주셔서 감사합니다. 당신이 볼 수 있듯이, 나는 getMessage를 리턴한다. (classpath 하에서 ffmpeg lib을 찾지 못했을 때이 예외를 받았다.) 이 애플릿에 대한 모든 인쇄물을 가져 오는 방법을 제안 해 주시겠습니까? – user2171669

+0

나는 cmd의 cmd 'dir'을 실행하고 '.../Desktop'을 수신하므로 지금은 앞으로 나아갑니다. – user2171669

답변

0

그러나 나는 몇 가지 .dll을로드 해요, 애플릿 리소스에서 애플릿 리소스를 임시 경로로 복사 한 다음이 경로에서로드합니다. DLL을 아래 보여 주었다 방법을 단지 안에 위치 : 내 경우 디렉토리와 파일의 이름을 (매개 변수로

enter image description here

LOADLIB 방법 복사 디스크에 .dll을 다음로드,이 방법은 수신 메서드 호출이 LOADLIB이다 ("/ 일/보안/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; 
} 

는, 애플릿이 올바른 서명해야하며 필요한 MANIFEST 권한 덧붙였다.

호프가 도움이 되었습니까?

+0

Tnx 당신이 당신의 대답을 많이 해드 리면서, 당신은 내 마지막 대답 할 수 있습니까? 내 질문에 댓글을 달았습니까? 미리 Tnx. – user2171669

관련 문제