简体   繁体   中英

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. I have compiled the first to a jar and placed it in the classpath of the second. I am calling the main class of the first jar from the application but all I see is a blank frame. The Main of my first Jar looks like this:

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. I do not want to run the jar like this although this is running the first program successfully:

Runtime.getRuntime().exec("java -jar lib/Myfirstjar.jar");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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