小程序和库

发布于 2024-10-10 01:45:38 字数 785 浏览 5 评论 0原文

我的小程序看不到外部库。一切都可以使用 appletviewer 进行,但不能使用浏览器。我已将包含 applet 类的 jar (TreC-Vis.jar)、TreC-Vis 使用的四个 jar 库以及带有以下 applet 标记的 html 文件放入“test_applet”文件夹中:

<applet code="gui.Gui" archive="TreC-Vis.jar,postgresql-8.4-701.jdbc4.jar,postgis_1.5.0.jar,jfreechart-1.0.13.jar,jcommon-1.0.16.jar" width="1024" height="768"> </applet>

Java 控制台为我提供了 java.io四个 jar 库中的每一个都出现 .FileNotFoundException。 我指定从相应的 Eclipse 项目导出 TreC-Vis.jar,其中我将这些库放在“src”包同一级别的“lib”文件夹中。

我写的小程序标签有什么问题? 阅读此处的教程

http://download.oracle.com/javase/tutorial /deployment/jar/downman.html

我一直在考虑将所有内容(小程序和库)放在一个 jar 中作为解决方案的可能性,但我需要注释中提到的“自定义代码”的一些示例。 提前致谢。

My applet doesn’t see the external libraries. Everything works using the appletviewer, but not using the browser. I’ve put in my “test_applet” folder the jar (TreC-Vis.jar) containing the applet classes, four jar libraries used by TreC-Vis and the html file with the following applet tag:

<applet code="gui.Gui" archive="TreC-Vis.jar,postgresql-8.4-701.jdbc4.jar,postgis_1.5.0.jar,jfreechart-1.0.13.jar,jcommon-1.0.16.jar" width="1024" height="768"> </applet>

Java console gives me a java.io.FileNotFoundException for each of the four jar libraries.
I specify that I exported TreC-Vis.jar from the corresponding Eclipse project, in which I put these libraries in a “lib” folder at the same level of the “src” package.

What’s wrong with the applet tag I wrote?
Reading the tutorial here

http://download.oracle.com/javase/tutorial/deployment/jar/downman.html

I’ve been considering the possibility to put everything, applet and libraries, in one jar as a solution, but I would need some example of the “custom code” mentioned in the Note.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千纸鹤 2024-10-17 01:45:39
jar cfm MyApplet.jar MyManifest.txt MyPackage1 MyPackage2 MyPackage3 

这就是我一直在寻找的线路。这样我就将外部库的类路径放入了清单中。

jar cfm MyApplet.jar MyManifest.txt MyPackage1 MyPackage2 MyPackage3 

This was the line I was looking for. This way I've put in my manifest the classpath of the external libraries.

橙味迷妹 2024-10-17 01:45:39

这是我的代码以及我如何在其中使用本机库。它在 Windows 中可以工作,但在 Linux 中不起作用,并且我收到

访问被拒绝(“java.lang.RuntimePermission”“loadLibrary.hello”)

这是我的 JNLP:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">

    <resources>
        <!-- Application Resources -->
        <j2se version="1.7+"
              href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="applet.jar" main="true" />
        <nativelib download="eager" href="libhello.jar"/>
    </resources>
    <applet-desc 
         name="Math Applet"
         main-class="NativeHelloApplet"
         width="10"
         height="1">
     </applet-desc>
     <update check="background"/>
</jnlp>

我的 Applet:

import java.security.*;
import javax.swing.*;

public class NativeHelloApplet extends JApplet
{
    public native String displayHelloWorld();
    public native int initPKE (int[] retVal); 

    public NativeHelloApplet() {   
    }

    public void init()
    {
        // privileged code goes here, for example:
        System.loadLibrary("hello");
        getContentPane().add(new JLabel("Test"));
        getContentPane().add(new JLabel(displayHelloWorld()));
    }
}

我的本机 .c 代码:

#include <jni.h>
#include "NativeHelloApplet.h"
#include <stdio.h>

JNIEXPORT jstring JNICALL
Java_NativeHelloApplet_displayHelloWorld(JNIEnv *env, jobject obj)
{
    return (*env)->NewStringUTF(env,"Hello world!\n");
}

我的 HTML 页面:

<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<script language="javascript" type="text/javascript" src="deployJava.js"></script>
 <script>
            var attributes = {
                id:         "sswSignApplet",
                code:       "NativeHelloApplet",
                width:      300,
                height:     60
            };
            var parameters = {jnlp_href:"launch.jnlp"}; <!-- Applet Parameters -->
            var version = "1.6"; <!-- Required Java Version -->
            deployJava.runApplet(attributes, parameters, version);
        </script>
</Body>
</Html> 

libhello.jar 包含我的本机代码的共享对象,并且与 html 和 jnlp 位于同一文件夹中。

当我将 hello.jar(包含 hello.dll)放入资源部分时,它在 Windows 中有效,但在 Linux 中我收到了上述错误。

Here is my code and how I have used native libraries in that. It does work in Windowes but it doesn't work in Linux and I receive

access denied("java.lang.RuntimePermission""loadLibrary.hello")

Here is my JNLP:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">

    <resources>
        <!-- Application Resources -->
        <j2se version="1.7+"
              href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="applet.jar" main="true" />
        <nativelib download="eager" href="libhello.jar"/>
    </resources>
    <applet-desc 
         name="Math Applet"
         main-class="NativeHelloApplet"
         width="10"
         height="1">
     </applet-desc>
     <update check="background"/>
</jnlp>

My Applet:

import java.security.*;
import javax.swing.*;

public class NativeHelloApplet extends JApplet
{
    public native String displayHelloWorld();
    public native int initPKE (int[] retVal); 

    public NativeHelloApplet() {   
    }

    public void init()
    {
        // privileged code goes here, for example:
        System.loadLibrary("hello");
        getContentPane().add(new JLabel("Test"));
        getContentPane().add(new JLabel(displayHelloWorld()));
    }
}

My native .c code :

#include <jni.h>
#include "NativeHelloApplet.h"
#include <stdio.h>

JNIEXPORT jstring JNICALL
Java_NativeHelloApplet_displayHelloWorld(JNIEnv *env, jobject obj)
{
    return (*env)->NewStringUTF(env,"Hello world!\n");
}

My HTML page:

<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<script language="javascript" type="text/javascript" src="deployJava.js"></script>
 <script>
            var attributes = {
                id:         "sswSignApplet",
                code:       "NativeHelloApplet",
                width:      300,
                height:     60
            };
            var parameters = {jnlp_href:"launch.jnlp"}; <!-- Applet Parameters -->
            var version = "1.6"; <!-- Required Java Version -->
            deployJava.runApplet(attributes, parameters, version);
        </script>
</Body>
</Html> 

libhello.jar contains the shared object of my native code and is located on the same folder as html and jnlp.

It works in windows when I put hello.jar(containing hello.dll) in resource section but in Linux I received the mentioned error.

失而复得 2024-10-17 01:45:38

我的小程序看不到外部库。 ..它们只是本机库,...class 文件..

好吧。如果那么,您的意思是 .dll、.so 等类型的文件中的“本机”,这对于小程序来说是有问题的,因为它们无法使用本机,除非它们已经安装在用户系统的适当目录中。

话虽如此,最近的发展允许我们使用 Java webstart (JWS) 部署嵌入式小程序。 JWS 使本地人的使用变得容易。只需将它们放在 Jar 文件的根目录中,然后将它们添加到(基于 XML 的)启动文件(文件类型 .jnlp)中的 nativelib 元素即可。

更好的是,JWS 可以将下载分成不同操作系统的资源,因此 Windows 获得 .dll 本机,而 *nix 获得 .so 本机。

JWS 提供了许多更有用的功能,但这里重要的是它们可以使本机可用于小程序。

在小程序中使用本机库需要信任该小程序。

My applet doesn’t see the external libraries. ..They are just native libraries, .. .class files ..

OK. If then, you mean 'natives' as in files of type .dll, .so etc., that is problematic for an applet in that they cannot use the natives unless they are already installed in the appropriate directory of the user system.

Having said that, recent developments allow us to deploy an embedded applet using Java webstart (JWS). JWS makes use of natives easy. Simply put them in the root of a Jar file and add them to a nativelib element in the (XML based) launch file (file type .jnlp).

Even better, JWS can separate the downloads into resources for different operating systems, so Windows gets the .dll natives, while *nix get the .so natives.

JWS offers many more useful features, but the important thing here is that they can make natives available to applets.

Use of native libs in an applet, requires the applet to be trusted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文