本地主机、Eclipse、java 小程序和 php 代码;小程序未运行
在此 PC 上运行 Apache/PHP。
我正在使用 Eclipse >>导出Java> JAR 文件或可运行 JAR 文件
我复制并粘贴了一些代码来测试在 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);
}
}
}
我尝试将其导出为简单的 Jar 和可运行的 Jar,并具有各种设置组合。
我唯一没有尝试过的就是创建我自己的清单,或者更确切地说,创建一个有效的清单。
这是我的 php 文件。没有 php 标签,即使我在那里有 php 代码,结果也是一样的:
<APPLET CODE="DrawingLines.class" WIDTH="250" HEIGHT="22" codebase="/Test/test.jar"> </APPLET>
我也尝试过:
<APPLET CODE="DrawingLines.class" WIDTH="250" HEIGHT="22"> </APPLET>
一般结果是这样的:
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)
我可以在 eclipse 中运行小程序。
如果它在外部环境中找不到该类,我假设我在创建 jar 的过程中搞砸了一些事情。我已经检查了该项目的 eclipse 运行配置。
在 Java Applet 下,它显示了一个以我的类 DrawingLines 命名的运行配置。
如果我尝试导出可运行的 jar,这里是它显示的启动配置,不确定是否是很重要,但第一类不存在。
知道这里发生了什么吗?
问候,
丹麦人
Running Apache/PHP on this PC.
I am using Eclipse >> Export Java > JAR file or Runnable JAR file
I copied and pasted some code to test running Java on a web server, here is the class.
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.
The only thing I haven't tried is creating my own manifest, or rather, one that works.
Here is my php file. There are no php tags, and the result was the same even when I had php code in there:
<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.
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. I've checked the eclipse Run Configurations for the project.
Under Java Applet, it shows a run configuration named after my class, 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.
Any idea what is going on here?
regards,
dane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想指示 jar 文件,则需要
archive
属性而不是codebase
属性。You need the
archive
attribute instead of thecodebase
attribute, if you want to indicate a jar file.