Load DLL library in my Applet
Asked Answered
F

0

0

When I try to run my applet on the server, it never seems to go out the first step, that is, loading libraries, and when I try to run on localhost, works perfectly

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

I put the jar files on the server in a visible HTTP path

<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>

Why when I try to run the applet on the server, it does not leave the first step?

@UPDATE

I found the line where the code don't move to the next line of code. String tmpDir = System.getProperty("java.io.tmpdir"); this line is where my code stop and still just in this line. Java is currently installed in server.

Finsen answered 26/9, 2012 at 15:4 Comment(8)
What errors are you getting? To do this from an applet within a browser it needs to be signed and run privileged. See here: https://mcmap.net/q/25141/-calling-a-dll-from-an-applet-via-jni/416627Workday
This is a problem. Without error when I tryied to run on server, but the applet still just in my first step. I signed the jar.Finsen
the line where the code doesn't move is a new thing to me :P If your applet throws an Exception, you have to paste the stack trace. System.getProperty() can throw a SecurityException a NPE or a IllegalArgumentException as you can seeDacy
Don't throw an Exception, in localhost works fine, but in the server, still processing this lines forever.Finsen
I have 4 package in my project com.colorfulwolf.webcamapplet, com.colorfulwolf.webcamapplet.gui, com.google.zxing, com.google.zxing.client.j2se. My applet runs in a classe that are in my com.colorfulwolf.webcamapplet package. I need put the another packages in my code attribute in <applet> tag?Finsen
What does it mean process this line forever? Are you stating the the thread blocks at System.getProperty()? How did you come to such a conclusion? It'd be a very strange thing indeedDacy
I put a JOptionPane after this line and didn't pass, and didin't pass in a catch statement.Finsen
In another Thread I saw that it can probably be a ClassNotFound issue. How can I tell to the server how to find the class path of a specific package/class ? In Eclipse, it is done transparently when I add DSJ jar library under Referenced Libraries build treeFinsen

© 2022 - 2024 — McMap. All rights reserved.