[英]Calling an external jar in classpath from a Java Application
I have two java Swing applications and I need to be able to execute the first one from the second. 我有两个java Swing应用程序,我需要能够从第二个应用程序执行第一个。 I have compiled the first to a jar and placed it in the classpath of the second.
我已经将第一个编译为jar并将其放在第二个的类路径中。 I am calling the main class of the first jar from the application but all I see is a blank frame.
我正在从应用程序调用第一个jar的主类,但是我看到的只是一个空白帧。 The Main of my first Jar looks like this:
我的第一个Jar的主菜单如下所示:
import java.awt.EventQueue;
import java.awt.Frame;
import javax.swing.JDialog;
public class AskulLibrary extends Frame implements Runnable{
final Frame frame;
public AskulLibrary(Frame frame) {
this.frame = frame;
}
public void run() {
frame.show();
}
public static void main(String[] args) {
JDialog.setDefaultLookAndFeelDecorated(true);
// Throw a nice little title page up on the screen first
new Splash().showSplash(3000);
EventQueue.invokeLater(new AskulLibrary(new JLibrary()));
}
}
I'm calling this main class from the second application like this: 我从第二个应用程序像这样调用这个主类:
import com.AskulLibrary;
import java.awt.Frame;
public class MainFrame extends JFrame{
AskulLibrary lib;
Frame frame;
public MainFrame(){
frame = new new Frame();
lib = new AskulLibrary (frame);
lib.run();
}
}
I'm doing something wrong somewhere because instead of initializing the first Jar I am getting an empty Frame. 我在某处做错了事,因为不是初始化第一个Jar,而是得到一个空的Frame。 I do not want to run the jar like this although this is running the first program successfully:
我不希望像这样运行jar,尽管它成功运行了第一个程序:
Runtime.getRuntime().exec("java -jar lib/Myfirstjar.jar");
why not to use implemented methods in official API, How to Create a Splash Screen 为什么不使用官方API中的已实现方法, 如何创建启动画面
(before Splash Screen
was implemented in official APIs) use JWindow
/ JDialog
but without using Runnable#Thread
, use the quite strict logics described about Event Dispatch Thread
in InitialThread instead, for both Top-Level Containers (在通过官方API实现
Splash Screen
之前)使用JWindow
/ JDialog
但不使用Runnable#Thread
,而是对两个顶级容器使用在InitialThread中描述的关于Event Dispatch Thread
的相当严格的逻辑
see my question about reverse order, similair, but with interactive logics, 看到我关于逆序的问题,类似,但具有交互逻辑,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.