更新时间:2021-12-26 02:36:05
从几英里远可以看到您没有在Class.forName
It's visible from a (few) mile(s) away you are not using the custom classloader beside Class.forName
由于已加载当前类MyProgram
的类加载器尝试加载org.eclipse.swt.graphics.Point,所以发生了ClassNoDefFoundError.
The ClassNoDefFoundError occurs since the classloader that has loaded current class MyProgram
attempts to load org.eclipse.swt.graphics.Point.
您需要通过Class.forName加载另一个类(称为启动器),然后从那里开始-实现一些接口(甚至可以运行)并调用它.
You need to load another class (call it launcher) via Class.forName and then start from there - implement some interface (even runnable will do) and call it.
编辑
如何做,这是一个简单的场景.
1.创建另一个名为mp.loader.Launcher
的类,该类实现了这样的Runnable.
How to do it, a simplistic scenario.
1. Create another class called mp.loader.Launcher
that implements Runnable like that.
public class Launcher implements Runnable{
public void run(){
org.eclipse.swt.graphics.Point pt = new org.eclipse.swt.graphics.Point(0, 0);
//whatever, start from here.
}
}
2.将其放在另一个名为swt-loader.jar的jar中.
2. Place it in another jar called swt-loader.jar.
在MyProgram类中使用:
in MyProgram class use:
loader.addJarToClasspath("swt-loader.jar");
Runnable r = (Runnable) Class.forName("mp.loader.Launcher", true, loader);
r.run();//there you have