创建使用外部JAR Java小程序 [英] Creating Java applet using external JARS

查看:207
本文介绍了创建使用外部JAR Java小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Java小程序在Netbeans中使用多个外部库。当我运行在NetBeans中applet.java文件它工作正常,我试图让一个网页相同的结果。

当我在build文件夹运行自动创建applet.html文件它不会加载外部库,尽管我在APPLET归档标签指定并将其移动到同一文件夹中。

下面是我的html文件:

 < HTML>
&所述; HEAD>
   < TITLE> Applet的HTML页面< / TITLE>
< / HEAD>
< BODY>< H3>< HR WIDTH =100%> Applet的HTML页面< HR WIDTH =100%>< / H3 GT&;&所述;差异无显着
< APPLET codeBase的=类code =小程序/ MyApplet.classWIDTH = 350 HEIGHT = 200归档=jcommon-1.0.17.jar,JFreeChart的-1.0.14.jar,sqljdbc4。罐子>< / APPLET>
&所述; /差异无显着&所述; HR WIDTH =100%>&下; FONT SIZE = -1>&下; I>可以通过NetBeans IDE的&下生成的; / I GT;&下; / FONT>
< / BODY>
< / HTML>

该库是第三方的Java(JFreeChart的和SQL-JDBC驱动程序)


解决方案

  

使用外部JAR创建Java小程序


一提到它们添加到小程序元素的归档属性。


 < APPLET codeBase的=类code =小程序/ MyApplet.classWIDTH = 350 HEIGHT = 200归档=jcommon-1.0.17。罐子,jfreechart的-1.0.14.jar,sqljdbc4.jar>< / APPLET>

重新格式化,让

 < APPLET
    codeBase的=类
    code =小程序/ MyApplet.class
    宽度= 350
    高度= 200
    归档=jcommon-1.0.17.jar,JFreeChart的-1.0.14.jar,sqljdbc4.jar>
< / APPLET>

1

  code =小程序/ MyApplet.class

应该是类的完全限定名。如果类名是 MyApplet 和包小程序,即转换为:

  code =applet.MyApplet

2

 归档=jcommon-1.0.17.jar,JFreeChart的-1.0.14.jar,sqljdbc4.jar>

只是检查,是在applet.MyApplet jcommon-1.0.17.jar

3

  codeBase的=类

这听起来很可怕。这是一个全面的网络应用程序与JSP / servlet的?如果是这样,我怀疑这条道路是错误的,因为它指向一个客户端(浏览器或)小程序不能访问服务器上的一个地方。试着做一个直接取(粘贴到浏览器地址栏中的地址预期,并创下'进入')上的每个小程序罐,如果 MyApplet.class 不在一个罐子,做松类文件单独检查。

I've created a Java Applet in Netbeans that uses several external libraries. When I run the applet.java file within Netbeans it works fine and I'm trying to get the same result in a web page.

When I run the automatically created applet.html-file in the build-folder it doesn't load the external library, even though I have specified them in APPLET archive-tag and moved them to the same folder.

Here is my html-file:

<HTML>
<HEAD>
   <TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>

<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

<P>
<APPLET codebase="classes" code="applet/MyApplet.class" width=350 height=200 archive="jcommon-1.0.17.jar,  jfreechart-1.0.14.jar, sqljdbc4.jar"></APPLET>
</P>

<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>

The libraries are 3rd-party java (jfreeChart and SQL-JDBC-driver)

解决方案

Creating Java applet using external JARS

Add a reference to them to the archive attribute of the applet element.


<APPLET codebase="classes" code="applet/MyApplet.class" width=350 height=200 archive="jcommon-1.0.17.jar,  jfreechart-1.0.14.jar, sqljdbc4.jar"></APPLET>

Reformatting that gives:

<APPLET 
    codebase="classes" 
    code="applet/MyApplet.class" 
    width=350 
    height=200 
    archive="jcommon-1.0.17.jar,  jfreechart-1.0.14.jar, sqljdbc4.jar">
</APPLET>

1.

    code="applet/MyApplet.class" 

Should be the fully qualified name of the class. If the class name is MyApplet and the package is applet, that translates to:

    code="applet.MyApplet" 

2.

    archive="jcommon-1.0.17.jar,  jfreechart-1.0.14.jar, sqljdbc4.jar">

Just checking, is applet.MyApplet in jcommon-1.0.17.jar?

3.

    codebase="classes" 

That sounds ominous. Is this a full-blown web-app with JSP/servlets? If so, I suspect that path is wrong, in that it is pointing to a place on the server that a client (browser or) applet cannot reach. Try doing a direct fetch (paste the expected address in the browser address bar, and hit 'enter') on each of the applet Jars, if the MyApplet.class is not in a Jar, do a separate check on the loose class file.

这篇关于创建使用外部JAR Java小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆