在我的Applet中加载DLL库

时间:2012-09-26 15:04:33

标签: java applet

当我尝试在服务器上运行我的applet时,它似乎永远不会出现第一步,即加载库,当我尝试在localhost上运行时,工作完美

CODE

private final static String DEFAULT_DOWNLOAD_PATH = "http://colorfulwolf.com/dev/cam/";

private final static String VERSION_ID = "1.0.0";

// note that this list is windows-specific, so this is not a generic
// solution that works on all OSes
private final static String[] LIBS = { "cv210.dll", "cvaux210.dll",
        "cxcore210.dll", "cxts210.dll", "highgui210.dll", "ml210.dll" };

private final static String LIB_ARCHIVE = "opencv21.zip";

public void loadWebcam() {
        loadingScreen.setMaxProgress(7);
        loadingScreen.setProgress(1, "Loading Librarys..");
        String tmpDir = System.getProperty("java.io.tmpdir");

        File faPath = new File(tmpDir + File.separator + "WebcamApplet_"
                + VERSION_ID.replaceAll("\\.", "-"));
        System.out.println(faPath);     
        System.setProperty("jna.library.path", faPath.getAbsolutePath());

        String downloadPath = this.getParameter("dll_path");
        if (downloadPath == null)
            downloadPath = DEFAULT_DOWNLOAD_PATH;

        try {
            prepareLibraries(faPath, downloadPath);
        } catch (Exception e) {
            e.printStackTrace();
            loadingScreen.setProgress(3, "Erro: " + e.getMessage());
            return;
        }
}


    private void prepareLibraries(File localPath, String downloadPath)
            throws Exception {
        if (localPath.exists()) {
            boolean libMissing = false;
            for (String lib : LIBS) {
                File libFile = new File(localPath.getAbsolutePath()
                        + File.separator + lib);
                if (!libFile.exists()) {
                    libMissing = true;
                    break;
                }
            }

            if (!libMissing)
                return; // We don't have to download
        }

        if (!localPath.exists() && !localPath.mkdirs()) // Error fatal!
            throw new Exception("Can't create the path: " + localPath);

        loadingScreen.setProgress(2, "Downloading library...");
        File file = new File(localPath.getAbsolutePath() + File.separator
                + LIB_ARCHIVE);
        String link = downloadPath + LIB_ARCHIVE;
        download(link, file);

        ZipFile zipFile = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();

        loadingScreen.setProgress(3, "Installing librarys..");
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.isDirectory())
                continue;

            File tar = new File(localPath.getAbsolutePath() + File.separator
                    + entry.getName());
            InputStream is = zipFile.getInputStream(entry);
            OutputStream os = new FileOutputStream(tar);
            copyStream(is, os);
            os.flush();
            os.close();
            is.close();
        }
        zipFile.close();

        file.delete();
        if (file.exists())
            file.deleteOnExit();
    }

我将jar文件放在服务器上的可见HTTP路径

<applet code="com.colorfulwolf.webcamapplet.WebcamApplet"        
    archive="http://www.netimoveis.com/teste.jar, http://www.netimoveis.com/core.jar, http://www.netimoveis.com/javacv.jar, http://www.netimoveis.com/javase.jar, http://www.netimoveis.com/jna.jar, http://www.netimoveis.com/customizer.jar, http://www.netimoveis.com/jmf.jar, http://www.netimoveis.com/meidaplayer.jar, http://www.netimoveis.com/multiplayer.jar, http://www.netimoveis.com/sound.jar"
    height="550" width="550">
</applet>

为什么当我尝试在服务器上运行applet时,它不会离开第一步?

@UPDATE

我找到了代码不会移动到下一行代码的行。 String tmpDir = System.getProperty("java.io.tmpdir");此行是我的代码停止的地方,仍然只是在这一行。 Java当前安装在服务器中。

0 个答案:

没有答案