简体   繁体   English

从Java应用程序在类路径中调用外部jar

[英]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");

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

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