简体   繁体   English

Localhost,Eclipse,java applet和php代码; 小程序未运行

[英]Localhost, Eclipse, java applets, and php code; applet not running

Running Apache/PHP on this PC. 在此PC上运行Apache / PHP。

I am using Eclipse >> Export Java > JAR file or Runnable JAR file 我正在使用Eclipse >>导出Java> JAR文件或Runnable JAR文件

I copied and pasted some code to test running Java on a web server, here is the class. 我复制并粘贴了一些代码以测试Web服务器上正在运行的Java,这是该类。

package com.dane;

import java.awt.*;

import javax.swing.JApplet;
import javax.swing.JFrame;

public class DrawingLines extends JApplet {

    public static void main(String[] args) {
        JApplet applet = new DrawingLines();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(applet);
        f.setSize(400, 400);
        f.setLocation(200, 200);
        applet.init();
        // If you override start method
        // applet.start();
        f.setVisible(true);
    }

    private static final long serialVersionUID = 1L;
    int width, height;

    public void init() {
        width = getSize().width;
        height = getSize().height;
        setBackground(Color.black);
    }

    public void paint(Graphics g) {
        g.setColor(Color.green);
        for (int i = 0; i < 10; ++i) {
            g.drawLine(width, height, i * width / 10, 0);
        }
    }
}

I have tried exporting it both as a simple Jar and a Runnable Jar, with all sorts of combinations of settings. 我尝试将其导出为具有各种设置组合的简单Jar和可运行Jar。

The only thing I haven't tried is creating my own manifest, or rather, one that works. 我唯一没有尝试过的事情就是创建自己的清单,或者说是可行的清单。

Here is my php file. 这是我的PHP文件。 There are no php tags, and the result was the same even when I had php code in there: 没有php标记,即使我在那里有php代码,结果也一样:

<APPLET CODE="DrawingLines.class" WIDTH="250" HEIGHT="22" codebase="/Test/test.jar"> </APPLET>

I have also tried: 我也尝试过:

<APPLET CODE="DrawingLines.class" WIDTH="250" HEIGHT="22"> </APPLET>

The general result is this: 总体结果是这样的:

load: class DrawingLines.class not found.
java.lang.ClassNotFoundException: DrawingLines.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I can run the applet within eclipse. 可以在Eclipse中运行小程序。

If it can't find the class in an external environment, I am assuming I am screwing up something during the creation of the jar. 如果它无法在外部环境中找到该类,那么我假设我在创建jar的过程中搞砸了一些东西。 I've checked the eclipse Run Configurations for the project. 我已经检查了该项目的Eclipse Run Configurations。

Under Java Applet, it shows a run configuration named after my class, DrawingLines. 在Java Applet下,它显示了以我的类DrawingLines命名的运行配置。 在此处输入图片说明

If I try to export a runnable jar, here are the launch configurations it shows, not sure if it is important but the class one isn't there. 如果我尝试导出可运行的jar,这是它显示的启动配置,不确定它是否很重要,但是不存在此类。 在此处输入图片说明

Any idea what is going on here? 知道这里发生了什么吗?

regards, 问候,

dane 丹犬

如果要指示一个jar文件,则需要使用archive属性而不是codebase属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM